Truly independent web browser
LibWeb: Reuse unchanged in-flow blocks in a block formatting context
Andreas Klinga1daa28786fb
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 5293dd350fc..f99782c80df 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -31,7 +31,7 @@ pub(crate) struct PendingTopMarginGroup {pub(crate) pinned_by_clearance: bool,}-#[derive(Debug, Default)]+#[derive(Clone, Debug, Default, PartialEq)]pub(crate) struct BlockMarginState {current_positive_collapsible_margin: CssPixels,current_negative_collapsible_margin: CssPixels,@@ -103,6 +103,29 @@ impl BlockMarginState {}}+/// What the probe for a stored in-flow layout found, and what storing the fresh layout needs.+#[expect(+ clippy::large_enum_variant,+ reason = "held on the stack while one child is laid out, where boxing would allocate for every child"+)]+enum InFlowReuse {+ Ineligible,+ Hit {+ entry: std::sync::Arc<in_flow_block_cache::InFlowBlockEntry>,+ fragment: std::sync::Arc<fragment_tree::Fragment>,+ },+ Store {+ key: in_flow_block_cache::InFlowBlockKey,+ validity: fc_run_cache::FcRunCacheValidity,+ flow_position: CssPixels,+ abspos_containing_block_info_contributions_received: u64,+ verify: Option<(+ std::sync::Arc<in_flow_block_cache::InFlowBlockEntry>,+ std::sync::Arc<fragment_tree::Fragment>,+ )>,+ },+}+#[derive(Clone, Copy, Debug, PartialEq, Eq)]enum FloatSide {Left,@@ -336,8 +359,8 @@ impl<'pass> BlockFormattingContext<'pass> {node: Node,offset: FfiCssPixelPoint,containing_line_box_fragment: Option<used_values::LineBoxFragmentCoordinate>,- ) {- formatting_context::place_child(&self.run, node, offset, containing_line_box_fragment);+ ) -> Option<fragment_tree::PlacedFragment> {+ formatting_context::place_child(&self.run, node, offset, containing_line_box_fragment)}fn register_contained_abspos_child(&self, node: Node, block_offset: CssPixels, coordinate_space_box: Node) {@@ -1707,6 +1730,20 @@ impl<'pass> BlockFormattingContext<'pass> {return;}+ let in_flow_reuse = match self.probe_in_flow_reuse(+ node,+ block_container,+ block_container_inline_size,+ input,+ containing_line_box_fragment,+ ) {+ InFlowReuse::Hit { entry, fragment } => {+ self.reuse_in_flow_child(node, block_container, &entry, fragment, bottom_of_lowest_margin_box);+ return;+ }+ attempt => attempt,+ };+self.margin_state.borrow_mut().add_margin(self.used(node).margin_top.get());@@ -2044,12 +2081,14 @@ impl<'pass> BlockFormattingContext<'pass> {}let dependency_was_not_reported_by_a_child_run = !has_independent_formatting_context;+ let mut depends_on_percentage_block_size = false;if dependency_was_not_reported_by_a_child_run {+ depends_on_percentage_block_size = self.sizing().resolve_percentage_block_size_dependency(node);formatting_context::propagate_percentage_block_size_dependency_to_containing_block(run.records,&self.run.callbacks,node,- self.sizing().resolve_percentage_block_size_dependency(node),+ depends_on_percentage_block_size,);}@@ -2063,9 +2102,8 @@ impl<'pass> BlockFormattingContext<'pass> {},);- if let Some(position) = pending_position {- self.place_child_on_line(node, position, containing_line_box_fragment);- }+ let placed = pending_position+ .and_then(|position| self.place_child_on_line(node, position, containing_line_box_fragment));if has_independent_formatting_context || !self.margins_collapse_through(node) {let mut margin_state = self.margin_state.borrow_mut();@@ -2094,6 +2132,224 @@ impl<'pass> BlockFormattingContext<'pass> {+ used.content_block_size.get()+ used.margin_box_bottom(used.uses_collapsing_borders_model.get()),);+ self.conclude_in_flow_reuse(in_flow_reuse, node, placed, depends_on_percentage_block_size);+ }++ /// Whether the layout of an in-flow child can be stored and reused by `InFlowBlockKey`: only a block container+ /// laid out in this run's own flow, where no float and no line clamp can read its position in the root.+ fn in_flow_child_may_be_reused(+ &self,+ node: Node,+ block_container: Node,+ containing_line_box_fragment: Option<used_values::LineBoxFragmentCoordinate>,+ ) -> bool {+ let facts = self.facts(node);+ let container_facts = self.facts(block_container);+ self.run.purpose == formatting_context::LayoutPurpose::Commit+ && self.run.layout_mode == LayoutMode::Normal+ && self.run.fragments.is_some()+ && !self.run.should_collect_devtools_layout_data+ && containing_line_box_fragment.is_none()+ && self.floats.borrow().is_empty()+ && !self.is_line_clamp_container+ && self.max_lines.get().is_none()+ && !self.laying_out_invisible_line_clamp_content.get()+ && formatting_context::formatting_context_type_created_by_box(facts).is_none()+ && facts.is_block_container()+ && !facts.is_anonymous_button_content_wrapper()+ && !facts.has_preferred_aspect_ratio()+ && self.style(node).clear() == clear::NONE+ && !container_facts.is_fieldset_box()+ && !container_facts.is_table_wrapper()+ }++ fn probe_in_flow_reuse(+ &self,+ node: Node,+ block_container: Node,+ block_container_inline_size: CssPixels,+ input: LayoutInput,+ containing_line_box_fragment: Option<used_values::LineBoxFragmentCoordinate>,+ ) -> InFlowReuse {+ if !self.in_flow_child_may_be_reused(node, block_container, containing_line_box_fragment) {+ return InFlowReuse::Ineligible;+ }+ let callbacks = &self.run.callbacks;+ let key = in_flow_block_cache::InFlowBlockKey::new(+ &self.run,+ input,+ block_container_inline_size,+ self.style(block_container).direction() == direction::RTL,+ self.margin_state.borrow().clone(),+ );+ let validity = fc_run_cache::run_root_validity(callbacks, node);+ let hit = callbacks+ .arena()+ .in_flow_block_cache_store()+ .matching(node.slot_index(), validity, &key)+ .and_then(|entry| {+ // NB: The committed subtree is reused only while it is the one the stored layout produced. A layout+ // whose fragments were superseded within its pass never committed them.+ let fragment = callbacks+ .arena()+ .with_current_committed_fragment(node, |fragment| {+ (fragment.identity == entry.fragment_identity).then(|| fragment.clone())+ })+ .flatten()?;+ Some((entry, fragment))+ });+ if let Some((entry, fragment)) = hit {+ if !in_flow_block_cache::verification_is_enabled() {+ return InFlowReuse::Hit { entry, fragment };+ }+ return InFlowReuse::Store {+ key,+ validity,+ flow_position: self.flow_position(),+ abspos_containing_block_info_contributions_received: self+ .abspos_containing_block_info_contributions_received(),+ verify: Some((entry, fragment)),+ };+ }+ InFlowReuse::Store {+ key,+ validity,+ flow_position: self.flow_position(),+ abspos_containing_block_info_contributions_received: self+ .abspos_containing_block_info_contributions_received(),+ verify: None,+ }+ }++ fn flow_position(&self) -> CssPixels {+ self.block_offset_of_current_block_container+ .get()+ .expect("a block container flow cursor is active")+ }++ fn abspos_containing_block_info_contributions_received(&self) -> u64 {+ self.run.fragments.as_deref().map_or(0, |fragments| {+ fragments.abspos_containing_block_info_contributions_received()+ })+ }++ fn reuse_in_flow_child(+ &self,+ node: Node,+ block_container: Node,+ entry: &in_flow_block_cache::InFlowBlockEntry,+ fragment: std::sync::Arc<fragment_tree::Fragment>,+ bottom_of_lowest_margin_box: &mut CssPixels,+ ) {+ self.run.callbacks.arena().layout_trace.reused_in_flow_subtree(node);+ let used = self.used(node);+ entry.cells.apply_to_record(used);+ if let Some(line_data) = &fragment.line_data {+ used.set_finished_line_data(line_data.clone());+ }+ let flow_position = self.flow_position();+ *self.margin_state.borrow_mut() = entry.outgoing_margins.clone();+ used.depends_on_percentage_block_size+ .set(entry.depends_on_percentage_block_size);+ formatting_context::propagate_percentage_block_size_dependency_to_containing_block(+ self.run.records,+ &self.run.callbacks,+ node,+ entry.depends_on_percentage_block_size,+ );+ let block_container_used = self.used(block_container);+ self.compute_inset(+ &self.run,+ node,+ geometry::LogicalSize {+ inline_size: block_container_used.content_inline_size.get(),+ block_size: block_container_used.content_block_size.get(),+ },+ );+ formatting_context::place_reused_child(+ &self.run,+ node,+ FfiCssPixelPoint {+ x: entry.offset_from_flow_position.x,+ y: entry.offset_from_flow_position.y + flow_position,+ },+ fragment,+ );+ self.block_offset_of_current_block_container+ .set(Some(flow_position + entry.flow_position_advance));+ *bottom_of_lowest_margin_box =+ (*bottom_of_lowest_margin_box).max(flow_position + entry.margin_box_bottom_from_flow_position);+ }++ fn conclude_in_flow_reuse(+ &self,+ attempt: InFlowReuse,+ node: Node,+ placed: Option<fragment_tree::PlacedFragment>,+ depends_on_percentage_block_size: bool,+ ) {+ let InFlowReuse::Store {+ key,+ validity,+ flow_position,+ abspos_containing_block_info_contributions_received,+ verify,+ } = attempt+ else {+ return;+ };+ let store = self.run.callbacks.arena().in_flow_block_cache_store();+ let Some(placed) = placed else {+ store.remove_entry(node.slot_index());+ return;+ };+ let used = self.used(node);+ // NB: A child whose border box has no block size may let margins collapse through it, which its parent+ // decides by looking at the child's own children.+ let reusable = !placed.exports_payloads+ && self.floats.borrow().is_empty()+ && self.abspos_containing_block_info_contributions_received()+ == abspos_containing_block_info_contributions_received+ && used.border_box_block_size(false) != CssPixels::default();+ let mut cells = used_values::UsedValuesCellState::capture(used);+ cells.has_content_offset = false;+ cells.content_offset = FfiCssPixelPoint::default();+ let content_offset = used.content_offset.get();+ let entry = in_flow_block_cache::InFlowBlockEntry {+ key,+ validity,+ cells,+ offset_from_flow_position: FfiCssPixelPoint {+ x: content_offset.x,+ y: content_offset.y - flow_position,+ },+ flow_position_advance: self.flow_position() - flow_position,+ outgoing_margins: self.margin_state.borrow().clone(),+ margin_box_bottom_from_flow_position: content_offset.y+ + used.content_block_size.get()+ + used.margin_box_bottom(used.uses_collapsing_borders_model.get())+ - flow_position,+ depends_on_percentage_block_size,+ fragment_identity: placed.fragment.identity,+ };+ if let Some((stored, committed)) = verify {+ let fragments = self.run.fragments.as_deref();+ let was_reused = |slot: u32| fragments.is_some_and(|fragments| fragments.subtree_was_reused(slot));+ in_flow_block_cache::verify_reuse(+ node,+ &stored,+ &committed,+ &entry,+ &placed.fragment,+ reusable,+ &was_reused,+ );+ }+ if reusable {+ store.store(node.slot_index(), entry);+ } else {+ store.remove_entry(node.slot_index());+ }}fn layout_block_level_children(diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rsindex 9061c56fdc4..56a34286713 100644--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs@@ -463,7 +463,7 @@ impl FcRunCacheArenaStore {}}-fn run_root_validity(callbacks: &LayoutPass<'_>, box_: Node) -> FcRunCacheValidity {+pub(super) fn run_root_validity(callbacks: &LayoutPass<'_>, box_: Node) -> FcRunCacheValidity {let data = NodeFacts::new(callbacks, box_).data();FcRunCacheValidity {slot_generation: data.slot_generation.get(),diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 4cad210767e..1e17df8314c 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -331,9 +331,9 @@ pub(crate) fn place_child(node: Node,offset: FfiCssPixelPoint,containing_line_box_fragment: Option<used_values::LineBoxFragmentCoordinate>,-) {+) -> Option<fragment_tree::PlacedFragment> {let containing_block = run.callbacks.in_flow_containing_block(node);- place_child_in_containing_block(run, node, containing_block, offset, containing_line_box_fragment);+ place_child_in_containing_block(run, node, containing_block, offset, containing_line_box_fragment)}pub(crate) fn place_child_in_containing_block(@@ -342,57 +342,91 @@ pub(crate) fn place_child_in_containing_block(containing_block: Node,offset: FfiCssPixelPoint,containing_line_box_fragment: Option<used_values::LineBoxFragmentCoordinate>,+) -> Option<fragment_tree::PlacedFragment> {+ let records = run.records;+ let callbacks = &run.callbacks;+ let used = records.used_values(node);+ set_placement(used, containing_block, offset);+ let fragments = run.fragments.as_deref()?;+ fragments.normalize_arrivals_for_placement(node, callbacks);+ loop {+ let batch = fragments.take_drainable_abspos(node, records, callbacks);+ if batch.is_empty() {+ break;+ }+ let engine = abspos_engine::AbsposEngine::for_run(run);+ for entry in batch {+ engine.layout_pending_child(run, entry);+ }+ }+ let node_facts = NodeFacts::new(callbacks, node);+ let own_anchor_candidate_border_box_rect = (node_facts.is_box() && node_facts.has_anchor_names()).then(|| {+ let collapsed = used.uses_collapsing_borders_model.get();+ CssPixelRect {+ x: used.content_offset.get().x - used.border_box_left(collapsed),+ y: used.content_offset.get().y - used.border_box_top(collapsed),+ width: used.border_box_inline_size(collapsed),+ height: used.border_box_block_size(collapsed),+ }+ });+ Some(fragments.build_fragment_for_placed_box(+ callbacks,+ node,+ (!containing_block.is_invalid()).then_some(containing_block),+ used,+ containing_block_is_sealed(records, containing_block),+ resolve_containing_line_box_index(records, callbacks, node, containing_block, containing_line_box_fragment),+ point_add(+ offset,+ committed_offset_delta_at_placement(run.purpose, records, callbacks, node, containing_block, used),+ ),+ own_anchor_candidate_border_box_rect,+ ))+}++/// Places an in-flow child whose committed subtree is reused as it is, with the committed fragment it was laid out+/// to. The child's record must already hold what its layout left in it.+pub(crate) fn place_reused_child(+ run: &FormattingContextRun,+ node: Node,+ offset: FfiCssPixelPoint,+ fragment: std::sync::Arc<fragment_tree::Fragment>,) {- let purpose = run.purpose;let records = run.records;let callbacks = &run.callbacks;- let fragments = run.fragments.as_deref();+ let containing_block = callbacks.in_flow_containing_block(node);let used = records.used_values(node);+ set_placement(used, containing_block, offset);+ let fragments = run+ .fragments+ .as_deref()+ .expect("a reused subtree is placed by a run that builds fragments");+ fragments.attach_reused_subtree(+ node,+ fragment,+ (!containing_block.is_invalid()).then_some(containing_block),+ used,+ containing_block_is_sealed(records, containing_block),+ point_add(+ offset,+ committed_offset_delta_at_placement(run.purpose, records, callbacks, node, containing_block, used),+ ),+ );+}++fn set_placement(used: &UsedValues, containing_block: Node, offset: FfiCssPixelPoint) {assert!(!used.has_content_offset.get());used.has_content_offset.set(true);used.content_offset.set(offset);used.placed_in.set(containing_block);used.seal_committed_box_metrics();- if let Some(fragments) = fragments {- fragments.normalize_arrivals_for_placement(node, callbacks);- loop {- let batch = fragments.take_drainable_abspos(node, records, callbacks);- if batch.is_empty() {- break;- }- let engine = abspos_engine::AbsposEngine::for_run(run);- for entry in batch {- engine.layout_pending_child(run, entry);- }- }- let containing_block_is_sealed = !containing_block.is_invalid()- && records- .used_values_if_owned(containing_block)- .is_none_or(|containing_block_used| containing_block_used.has_content_offset.get());- let node_facts = NodeFacts::new(callbacks, node);- let own_anchor_candidate_border_box_rect = (node_facts.is_box() && node_facts.has_anchor_names()).then(|| {- let collapsed = used.uses_collapsing_borders_model.get();- CssPixelRect {- x: used.content_offset.get().x - used.border_box_left(collapsed),- y: used.content_offset.get().y - used.border_box_top(collapsed),- width: used.border_box_inline_size(collapsed),- height: used.border_box_block_size(collapsed),- }- });- fragments.build_fragment_for_placed_box(- callbacks,- node,- (!containing_block.is_invalid()).then_some(containing_block),- used,- containing_block_is_sealed,- resolve_containing_line_box_index(records, callbacks, node, containing_block, containing_line_box_fragment),- point_add(- offset,- committed_offset_delta_at_placement(purpose, records, callbacks, node, containing_block, used),- ),- own_anchor_candidate_border_box_rect,- );- }+}++fn containing_block_is_sealed(records: &RunRecords, containing_block: Node) -> bool {+ !containing_block.is_invalid()+ && records+ .used_values_if_owned(containing_block)+ .is_none_or(|containing_block_used| containing_block_used.has_content_offset.get())}/// The line box index to record for atomic inlines whose containing linediff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rsindex 75bed187d27..327bebf1d9d 100644--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs@@ -117,6 +117,47 @@ impl Fragment {&& self.clamped_content_is_scrollable_overflow == previous.clamped_content_is_scrollable_overflow}+ /// Whether this fragment's subtree came out of layout like `previous`, ignoring which allocations hold the pieces.+ /// A subtree this layout reused as a whole, as `was_reused` says by slot, carries no descendants, and compares+ /// equal down to its root.+ pub(crate) fn lays_out_like(&self, previous: &Fragment, was_reused: &impl Fn(u32) -> bool) -> bool {+ let same_line_data = match (&self.line_data, &previous.line_data) {+ (None, None) => true,+ (Some(left), Some(right)) => left == right,+ _ => false,+ };+ self.node == previous.node+ && self.content_inline_size == previous.content_inline_size+ && self.content_block_size == previous.content_block_size+ && self.margin_left == previous.margin_left+ && self.margin_right == previous.margin_right+ && self.margin_top == previous.margin_top+ && self.margin_bottom == previous.margin_bottom+ && self.border_left == previous.border_left+ && self.border_right == previous.border_right+ && self.border_top == previous.border_top+ && self.border_bottom == previous.border_bottom+ && self.padding_left == previous.padding_left+ && self.padding_right == previous.padding_right+ && self.padding_top == previous.padding_top+ && self.padding_bottom == previous.padding_bottom+ && self.uses_collapsing_borders_model == previous.uses_collapsing_borders_model+ && self.svg == previous.svg+ && self.has_line_clamp_point == previous.has_line_clamp_point+ && self.is_invisible_for_line_clamp == previous.is_invisible_for_line_clamp+ && same_line_data+ && ((self.children.is_empty() && was_reused(self.node.slot_index()))+ || (self.children.len() == previous.children.len()+ && self+ .children+ .iter()+ .zip(&previous.children)+ .all(|(link, previous_link)| {+ link.has_same_placement(previous_link)+ && link.fragment.lays_out_like(&previous_link.fragment, was_reused)+ })))+ }+pub(crate) fn has_same_child_placements(&self, previous: &Fragment) -> bool {self.children.len() == previous.children.len()&& self@@ -415,6 +456,12 @@ fn snapshot_fragment(std::sync::Arc::new(fragment)}+/// The fragment a placement built, and whether anything from its subtree went on to its containing block.+pub(crate) struct PlacedFragment {+ pub(crate) fragment: std::sync::Arc<Fragment>,+ pub(crate) exports_payloads: bool,+}+pub(crate) struct PlacementData {pub(crate) committed_offset: FfiCssPixelPoint,pub(crate) inset_left: CssPixels,@@ -477,19 +524,23 @@ pub(crate) struct CompletedPassFragments {impl CompletedPassFragments {pub(crate) fn links_by_slot(&self) -> HashMap<u32, &FragmentLink> {- fn insert_links<'tree>(links: &'tree [FragmentLink], links_by_slot: &mut HashMap<u32, &'tree FragmentLink>) {+ fn insert_links<'tree>(+ links: &'tree [FragmentLink],+ reused_subtree_roots: &HashSet<u32>,+ links_by_slot: &mut HashMap<u32, &'tree FragmentLink>,+ ) {for link in links {- let previous = links_by_slot.insert(link.fragment.node.slot_index(), link);- assert!(- previous.is_none(),- "two fragments claim slot {}",- link.fragment.node.slot_index()- );- insert_links(&link.fragment.children, links_by_slot);+ let slot = link.fragment.node.slot_index();+ let previous = links_by_slot.insert(slot, link);+ assert!(previous.is_none(), "two fragments claim slot {slot}");+ // NB: Commit stops at a reused subtree's root, so nothing looks up the links below it.+ if !reused_subtree_roots.contains(&slot) {+ insert_links(&link.fragment.children, reused_subtree_roots, links_by_slot);+ }}}let mut links_by_slot = HashMap::default();- insert_links(&self.roots, &mut links_by_slot);+ insert_links(&self.roots, &self.reused_subtree_roots, &mut links_by_slot);links_by_slot}@@ -533,6 +584,8 @@ struct RunFragmentBuilderInner {anchor_candidates_at_root: Vec<AnchorCandidate>,inline_containing_block_rects_at_root: Vec<InlineContainingBlockRect>,abspos_containing_block_info_contributions: Vec<AbsposContainingBlockInfoContribution>,+ /// How many abspos containing block info contributions the run has received, whether or not they are still listed.+ abspos_containing_block_info_contributions_received: u64,top_scope_links: Vec<FragmentLink>,reused_subtree_roots: HashSet<u32>,}@@ -706,6 +759,7 @@ impl RunFragmentBuilder {inner.abspos_containing_block_info_contributions.push(AbsposContainingBlockInfoContribution { child_box, info });+ inner.abspos_containing_block_info_contributions_received += 1;}pub(crate) fn find_abspos_containing_block_info(@@ -859,6 +913,8 @@ impl RunFragmentBuilder {pending_fragment.inline_containing_block_rects.extend(root.propagated_inline_containing_block_rects);+ inner.abspos_containing_block_info_contributions_received +=+ root.propagated_abspos_containing_block_info.len() as u64;inner.abspos_containing_block_info_contributions.extend(root.propagated_abspos_containing_block_info);@@ -875,7 +931,7 @@ impl RunFragmentBuilder {containing_line_box_index: Option<usize>,committed_offset: FfiCssPixelPoint,own_anchor_candidate_border_box_rect: Option<CssPixelRect>,- ) {+ ) -> PlacedFragment {let mut inner = self.inner.borrow_mut();let slot = node.slot_index();debug_assert!(@@ -892,11 +948,16 @@ impl RunFragmentBuilder {.pending_fragments.remove(&slot).unwrap_or_else(|| PendingFragment::new(node));+ let fragment = snapshot_fragment(callbacks, node, children, used);let link = link_fragment(- snapshot_fragment(callbacks, node, children, used),+ fragment.clone(),PlacementData::from_record(used, containing_line_box_index, committed_offset),);self.attach(&mut inner, link, containing_block, containing_block_is_sealed);+ let exports_payloads = !pending_abspos_from_placed_box.is_empty()+ || !anchor_candidates_from_placed_box.is_empty()+ || !inline_containing_block_rects_from_placed_box.is_empty()+ || own_anchor_candidate_border_box_rect.is_some();let content_offset = used.content_offset.get();for mut entry in pending_abspos_from_placed_box {debug_assert!(@@ -938,6 +999,42 @@ impl RunFragmentBuilder {None => inner.inline_containing_block_rects_at_root.push(payload),}}+ PlacedFragment {+ fragment,+ exports_payloads,+ }+ }++ /// Places the committed fragment of a box whose subtree is reused as it is. Commit stops at the box, so its+ /// committed descendants stay as they are.+ pub(crate) fn attach_reused_subtree(+ &self,+ node: crate::layout::node_data::NodeSlotId,+ fragment: std::sync::Arc<Fragment>,+ containing_block: Option<crate::layout::node_data::NodeSlotId>,+ used: &UsedValues,+ containing_block_is_sealed: bool,+ committed_offset: FfiCssPixelPoint,+ ) {+ let mut inner = self.inner.borrow_mut();+ let slot = node.slot_index();+ debug_assert!(+ !inner.child_roots_awaiting_placement.contains_key(&slot) && !inner.pending_fragments.contains_key(&slot),+ "a reused subtree's box has fragments of its own in this run (slot {slot})"+ );+ let link = link_fragment(fragment, PlacementData::from_record(used, None, committed_offset));+ self.attach(&mut inner, link, containing_block, containing_block_is_sealed);+ inner.reused_subtree_roots.insert(slot);+ }++ /// How many abspos containing block contributions the run has collected so far.+ /// How many abspos containing block info contributions the run has received so far, which only grows.+ pub(crate) fn abspos_containing_block_info_contributions_received(&self) -> u64 {+ self.inner.borrow().abspos_containing_block_info_contributions_received+ }++ pub(crate) fn subtree_was_reused(&self, slot: u32) -> bool {+ self.inner.borrow().reused_subtree_roots.contains(&slot)}fn attach(diff --git a/Libraries/LibWeb/Rust/src/layout/in_flow_block_cache.rs b/Libraries/LibWeb/Rust/src/layout/in_flow_block_cache.rsnew file mode 100644index 00000000000..26ccd417f7c--- /dev/null+++ b/Libraries/LibWeb/Rust/src/layout/in_flow_block_cache.rs@@ -0,0 +1,162 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! Reuse of an in-flow block-level child of a block formatting context whose subtree did not change, moved to where+//! the flow now puts it. A block container that does not establish a formatting context is laid out inside its+//! parent's run, so the formatting context run cache cannot see it: besides its layout input, it reads the margins+//! its preceding siblings left open and the flow position, and it leaves margins and a flow position behind.++use super::*;++/// Everything the layout of an in-flow block container and its subtree reads from outside that subtree, apart from+/// the flow position it starts at. Reuse moves the stored layout by the difference in flow position.+///+/// NB: Reuse is exact only while this key covers every such read. A new read of block formatting context or+/// containing block state inside the in-flow child path must be added here. Floats and line clamping read the+/// position in the formatting context root; neither may be present for an entry to be stored or used.+#[derive(Clone, PartialEq)]+pub(super) struct InFlowBlockKey {+ pub(super) input: LayoutInput,+ pub(super) containing_block_inline_size: CssPixels,+ pub(super) containing_block_is_right_to_left: bool,+ pub(super) incoming_margins: block_formatting_context::BlockMarginState,+ pub(super) run_root: Node,+ pub(super) treat_block_axis_percentage_insets_as_auto_beyond_root: bool,+ pub(super) initial_containing_block_size: (CssPixels, CssPixels),+ pub(super) document_in_quirks_mode: bool,+}++impl InFlowBlockKey {+ pub(super) fn new(+ run: &FormattingContextRun<'_>,+ input: LayoutInput,+ containing_block_inline_size: CssPixels,+ containing_block_is_right_to_left: bool,+ incoming_margins: block_formatting_context::BlockMarginState,+ ) -> Self {+ Self {+ input: LayoutInput {+ content_box_position_in_bfc_root: None,+ ..input+ },+ containing_block_inline_size,+ containing_block_is_right_to_left,+ incoming_margins,+ run_root: run.box_,+ treat_block_axis_percentage_insets_as_auto_beyond_root: run+ .treat_block_axis_percentage_insets_as_auto_beyond_root,+ initial_containing_block_size: (+ run.callbacks.initial_containing_block_inline_size,+ run.callbacks.initial_containing_block_block_size,+ ),+ document_in_quirks_mode: run.callbacks.document_in_quirks_mode,+ }+ }+}++/// What the layout of an in-flow block container leaves behind for its parent, relative to the flow position it+/// started at.+#[derive(Clone)]+pub(super) struct InFlowBlockEntry {+ pub(super) key: InFlowBlockKey,+ pub(super) validity: fc_run_cache::FcRunCacheValidity,+ /// The child's record as it was before its placement.+ pub(super) cells: used_values::UsedValuesCellState,+ pub(super) offset_from_flow_position: FfiCssPixelPoint,+ pub(super) flow_position_advance: CssPixels,+ pub(super) outgoing_margins: block_formatting_context::BlockMarginState,+ pub(super) margin_box_bottom_from_flow_position: CssPixels,+ pub(super) depends_on_percentage_block_size: bool,+ /// The fragment the stored layout placed. The committed subtree is reused only while it is still that fragment.+ pub(super) fragment_identity: u64,+}++/// Per-document store of in-flow block layouts, one entry per slot, surviving across layout passes on the node arena.+#[derive(Clone, Default)]+pub(crate) struct InFlowBlockCacheStore {+ entries: RefCell<Vec<Option<std::sync::Arc<InFlowBlockEntry>>>>,+}++impl InFlowBlockCacheStore {+ pub(super) fn matching(+ &self,+ slot: u32,+ validity: fc_run_cache::FcRunCacheValidity,+ key: &InFlowBlockKey,+ ) -> Option<std::sync::Arc<InFlowBlockEntry>> {+ let entries = self.entries.borrow();+ let entry = entries.get(slot as usize)?.as_ref()?;+ (entry.validity == validity && entry.key == *key).then(|| entry.clone())+ }++ pub(super) fn store(&self, slot: u32, entry: InFlowBlockEntry) {+ let mut entries = self.entries.borrow_mut();+ if entries.len() <= slot as usize {+ entries.resize_with(slot as usize + 1, || None);+ }+ // An entry nothing else holds is written in place rather than allocated again.+ if let Some(existing) = entries[slot as usize].as_mut().and_then(std::sync::Arc::get_mut) {+ *existing = entry;+ return;+ }+ entries[slot as usize] = Some(std::sync::Arc::new(entry));+ }++ pub(crate) fn remove_entry(&self, slot: u32) {+ if let Some(entry) = self.entries.borrow_mut().get_mut(slot as usize) {+ *entry = None;+ }+ }+}++/// Whether every in-flow reuse also lays the child out and checks that both agree.+pub(super) fn verification_is_enabled() -> bool {+ static ENABLED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();+ *ENABLED.get_or_init(|| std::env::var_os("LIBWEB_VERIFY_IN_FLOW_REUSE").is_some())+}++pub(super) fn verify_reuse(+ node: Node,+ stored: &InFlowBlockEntry,+ committed: &fragment_tree::Fragment,+ fresh: &InFlowBlockEntry,+ fresh_fragment: &fragment_tree::Fragment,+ fresh_is_reusable: bool,+ was_reused: &impl Fn(u32) -> bool,+) {+ assert!(+ fresh_is_reusable,+ "a reused in-flow layout of {node:?} is no longer reusable when laid out"+ );+ assert_eq!(+ stored.cells, fresh.cells,+ "the reused record of {node:?} differs from its layout"+ );+ assert_eq!(+ stored.offset_from_flow_position, fresh.offset_from_flow_position,+ "the reused offset of {node:?} differs from its layout"+ );+ assert_eq!(+ stored.flow_position_advance, fresh.flow_position_advance,+ "the reused flow advance of {node:?} differs from its layout"+ );+ assert!(+ stored.outgoing_margins == fresh.outgoing_margins,+ "the reused outgoing margins of {node:?} differ from its layout"+ );+ assert_eq!(+ stored.margin_box_bottom_from_flow_position, fresh.margin_box_bottom_from_flow_position,+ "the reused margin box bottom of {node:?} differs from its layout"+ );+ assert_eq!(+ stored.depends_on_percentage_block_size, fresh.depends_on_percentage_block_size,+ "the reused percentage block size dependency of {node:?} differs from its layout"+ );+ assert!(+ fresh_fragment.lays_out_like(committed, was_reused),+ "the reused subtree of {node:?} differs from its layout"+ );+}diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex 3a0da7a8acd..df09f7d09f5 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -1254,6 +1254,7 @@ pub(crate) struct LayoutNodeArena {/// under a key so that it survives the node's identity being retired and re-issued.next_rows_built_for_same_node: Vec<Cell<NodeSlotId>>,fc_run_cache_store: super::fc_run_cache::FcRunCacheArenaStore,+ in_flow_block_cache_store: super::in_flow_block_cache::InFlowBlockCacheStore,pub(super) layout_trace: super::trace::LayoutTrace,pub(super) innermost_run: Cell<(NodeSlotId, NodeSlotId)>,pub(crate) paintable_rows: crate::painting::paintable_rows::PaintableRowStore,@@ -1367,6 +1368,7 @@ impl LayoutNodeArena {svg_paint_resources: crate::painting::svg_paint_resources::SvgPaintResources::default(),next_rows_built_for_same_node: Vec::new(),fc_run_cache_store: super::fc_run_cache::FcRunCacheArenaStore::default(),+ in_flow_block_cache_store: super::in_flow_block_cache::InFlowBlockCacheStore::default(),layout_trace: super::trace::LayoutTrace::default(),innermost_run: Cell::new((NodeSlotId::INVALID, NodeSlotId::INVALID)),paintable_rows: crate::painting::paintable_rows::PaintableRowStore::default(),@@ -1436,6 +1438,10 @@ impl LayoutNodeArena {&self.fc_run_cache_store}+ pub(crate) fn in_flow_block_cache_store(&self) -> &super::in_flow_block_cache::InFlowBlockCacheStore {+ &self.in_flow_block_cache_store+ }+pub(crate) fn end_layout_pass(&self) {self.sweep_stale_fc_run_cache_entries();}@@ -1709,6 +1715,7 @@ impl LayoutNodeArena {self.owned_image_natural_sizes.get_mut().remove(&id);self.owned_image_providers.get_mut().remove(&id);self.fc_run_cache_store.remove_entry(index);+ self.in_flow_block_cache_store.remove_entry(index);self.remove_layout_update_flag_node(id);self.raw_table_column_spans.get_mut().remove(&id);if self.replaced_paint_facts.get_mut().contains_key(&id) {@@ -4839,7 +4846,7 @@ impl LayoutNodeArena {pub(crate) fn with_current_committed_fragment<R>(&self,node: NodeSlotId,- read: impl FnOnce(&super::fragment_tree::Fragment) -> R,+ read: impl FnOnce(&std::sync::Arc<super::fragment_tree::Fragment>) -> R,) -> Option<R> {self.paintable_rows.with_current_committed_fragment(node.slot_index(),@@ -5206,6 +5213,8 @@ impl LayoutNodeArena {self.fragment_cache_epoch_changed_during_layout_pass.set(true);}self.fc_run_cache_store.note_invalidated_entry(node);+ // NB: An in-flow block entry is valid for one epoch only, so it never matches again.+ self.in_flow_block_cache_store.remove_entry(node.slot_index());}pub(crate) fn note_structural_change_at_and_above(&self, node: NodeSlotId) {diff --git a/Libraries/LibWeb/Rust/src/layout/mod.rs b/Libraries/LibWeb/Rust/src/layout/mod.rsindex ed8205b8afe..bf176588299 100644--- a/Libraries/LibWeb/Rust/src/layout/mod.rs+++ b/Libraries/LibWeb/Rust/src/layout/mod.rs@@ -24,6 +24,7 @@ pub(crate) mod generated_content;pub mod geometry;pub mod grid_formatting_context;mod host_tables;+mod in_flow_block_cache;pub mod inline_content;pub(crate) mod inline_formatting_context;pub mod inline_level_iterator;diff --git a/Libraries/LibWeb/Rust/src/layout/trace.rs b/Libraries/LibWeb/Rust/src/layout/trace.rsindex c2b4f4878f0..c4cfaac82aa 100644--- a/Libraries/LibWeb/Rust/src/layout/trace.rs+++ b/Libraries/LibWeb/Rust/src/layout/trace.rs@@ -138,6 +138,11 @@ impl LayoutTrace {}}+ /// An in-flow block whose subtree is reused from the previous layout, moved to where the flow now puts it.+ pub(super) fn reused_in_flow_subtree(&self, node: NodeSlotId) {+ drop(self.scope("", Some(node), || " REUSE IN-FLOW SUBTREE".into()));+ }+pub(super) fn run(&self,root: NodeSlotId,diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rsindex 904ae09eee6..43ee928c47e 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs@@ -560,7 +560,7 @@ impl PaintableRowStore {layout_slot_index: u32,layout_slot_generation: u8,geometry_epoch: u32,- read: impl FnOnce(&fragment_tree::Fragment) -> R,+ read: impl FnOnce(&std::sync::Arc<fragment_tree::Fragment>) -> R,) -> Option<R> {let slots = self.committed_fragment_links.borrow();let slot = slots.get(layout_slot_index as usize)?;diff --git a/Meta/Linters/check_rust_process_wide_state.py b/Meta/Linters/check_rust_process_wide_state.pyindex 805b73e31bf..20fd0eb0339 100755--- a/Meta/Linters/check_rust_process_wide_state.py+++ b/Meta/Linters/check_rust_process_wide_state.py@@ -112,6 +112,7 @@ RENDER_STATE_ALLOWED = {"css/style/mod.rs:SELECTOR_TRUTH_DERIVATION","css/style/mod.rs:STYLE_ANSWER_PATCH","css/style/mod.rs:STYLE_PLAN_PROVENANCE",+ "layout/in_flow_block_cache.rs:ENABLED","render_state/clock/hover.rs:LOGS",],),diff --git a/Tests/LibWeb/Text/input/display_list/svg-resource-clip-content-change.html b/Tests/LibWeb/Text/input/display_list/svg-resource-clip-content-change.htmlindex 7196af35c96..61cfb59c4eb 100644--- a/Tests/LibWeb/Text/input/display_list/svg-resource-clip-content-change.html+++ b/Tests/LibWeb/Text/input/display_list/svg-resource-clip-content-change.html@@ -30,7 +30,7 @@ displayListTest({name: "widen the clip content",mutate: () => { document.getElementById("clip-rect").setAttribute("width", "200"); },expect: `- damage: rows=8 moved=0 order=1 eligibility=0 all=false+ damage: rows=8 moved=0 order=0 eligibility=0 all=false@canvas RECORD (empty)@viewport ASSEMBLE@viewport/preamble COPY@@ -58,11 +58,11 @@ displayListTest({BlockContainer(anonymous)/scroll-metadata COPYBlockContainer(anonymous)/background COPYBlockContainer(anonymous)/border COPY- SVGSVGBox<svg>#svg/descendants(background-and-borders) REPLAN+ SVGSVGBox<svg>#svg/descendants(background-and-borders) ASSEMBLEBlockContainer<DIV>#other/descendants(background-and-borders) COPYBlockContainer<BODY>#body/descendants(inline-background-and-borders) ASSEMBLEBlockContainer(anonymous)/descendants(inline-background-and-borders) ASSEMBLE- SVGSVGBox<svg>#svg/descendants(inline-background-and-borders) REPLAN+ SVGSVGBox<svg>#svg/descendants(inline-background-and-borders) ASSEMBLEBlockContainer<DIV>#other/descendants(inline-background-and-borders) COPYBlockContainer<HTML>#html/foreground/hit-test COPYBlockContainer<HTML>#html/foreground COPY@@ -71,7 +71,7 @@ displayListTest({BlockContainer<BODY>#body/foreground COPYBlockContainer(anonymous)/descendants(foreground) ASSEMBLEBlockContainer(anonymous)/foreground/hit-test COPY- SVGSVGBox<svg>#svg REPLAN+ SVGSVGBox<svg>#svg ASSEMBLESVGSVGBox<svg>#svg/background/hit-test RECORDSVGSVGBox<svg>#svg/scroll-metadata RECORD (empty)SVGSVGBox<svg>#svg/background SKIP@@ -90,7 +90,7 @@ displayListTest({SVGGeometryBox<rect>#clipped/foreground/hit-test RECORDSVGGeometryBox<rect>#clipped/foreground RECORDBlockContainer(anonymous)/foreground COPY- SVGSVGBox<svg>#svg/descendants(foreground) REPLAN+ SVGSVGBox<svg>#svg/descendants(foreground) ASSEMBLEBlockContainer(anonymous)/outline COPYBlockContainer(anonymous)/overlay/hit-test COPYBlockContainer(anonymous)/overlay COPYdiff --git a/Tests/LibWeb/Text/input/display_list/svg-resource-mask-content-change.html b/Tests/LibWeb/Text/input/display_list/svg-resource-mask-content-change.htmlindex e14195f12ea..51aab13c8db 100644--- a/Tests/LibWeb/Text/input/display_list/svg-resource-mask-content-change.html+++ b/Tests/LibWeb/Text/input/display_list/svg-resource-mask-content-change.html@@ -32,7 +32,7 @@ displayListTest({name: "widen the mask content",mutate: () => { document.getElementById("mask-rect").setAttribute("width", "200"); },expect: `- damage: rows=9 moved=0 order=1 eligibility=0 all=false+ damage: rows=9 moved=0 order=0 eligibility=0 all=false@canvas RECORD (empty)@viewport ASSEMBLE@viewport/preamble COPY@@ -60,11 +60,11 @@ displayListTest({BlockContainer(anonymous)/scroll-metadata COPYBlockContainer(anonymous)/background COPYBlockContainer(anonymous)/border COPY- SVGSVGBox<svg>#svg/descendants(background-and-borders) REPLAN+ SVGSVGBox<svg>#svg/descendants(background-and-borders) ASSEMBLEBlockContainer<DIV>#other/descendants(background-and-borders) COPYBlockContainer<BODY>#body/descendants(inline-background-and-borders) ASSEMBLEBlockContainer(anonymous)/descendants(inline-background-and-borders) ASSEMBLE- SVGSVGBox<svg>#svg/descendants(inline-background-and-borders) REPLAN+ SVGSVGBox<svg>#svg/descendants(inline-background-and-borders) ASSEMBLEBlockContainer<DIV>#other/descendants(inline-background-and-borders) COPYBlockContainer<HTML>#html/foreground/hit-test COPYBlockContainer<HTML>#html/foreground COPY@@ -73,7 +73,7 @@ displayListTest({BlockContainer<BODY>#body/foreground COPYBlockContainer(anonymous)/descendants(foreground) ASSEMBLEBlockContainer(anonymous)/foreground/hit-test COPY- SVGSVGBox<svg>#svg REPLAN+ SVGSVGBox<svg>#svg ASSEMBLESVGSVGBox<svg>#svg/background/hit-test RECORDSVGSVGBox<svg>#svg/scroll-metadata RECORD (empty)SVGSVGBox<svg>#svg/background SKIP@@ -95,7 +95,7 @@ displayListTest({SVGGeometryBox<rect>#masked/foreground/hit-test RECORDSVGGeometryBox<rect>#masked/foreground RECORDBlockContainer(anonymous)/foreground COPY- SVGSVGBox<svg>#svg/descendants(foreground) REPLAN+ SVGSVGBox<svg>#svg/descendants(foreground) ASSEMBLEBlockContainer(anonymous)/outline COPYBlockContainer(anonymous)/overlay/hit-test COPYBlockContainer(anonymous)/overlay COPYdiff --git a/Tests/LibWeb/Text/input/layout-in-flow-reuse.html b/Tests/LibWeb/Text/input/layout-in-flow-reuse.htmlindex db6ff0f088a..5ae0cf85c8a 100644--- a/Tests/LibWeb/Text/input/layout-in-flow-reuse.html+++ b/Tests/LibWeb/Text/input/layout-in-flow-reuse.html@@ -28,8 +28,8 @@BlockContainer<HTML>/block RUN (cache=miss)BlockContainer<DIV>#list.scenario/block RUN (cache=miss)BlockContainer<DIV>.toggle/block REUSE SUBTREE- BlockContainer<DIV>.toggle/block REUSE SUBTREE- BlockContainer<DIV>.toggle/block REUSE SUBTREE+ ListItemBox<LI>#li3 REUSE IN-FLOW SUBTREE+ ListItemBox<LI>#li4 REUSE IN-FLOW SUBTREEBlockContainer<DIV>#text.scenario/block REUSE SUBTREEBlockContainer<DIV>#margins.scenario/block REUSE SUBTREEBlockContainer<DIV>#abspos-scenario.scenario/block REPLAY FRAGMENTS@@ -52,6 +52,9 @@BlockContainer<HTML>/block RUN (cache=miss)BlockContainer<DIV>#list.scenario/block REUSE SUBTREEBlockContainer<DIV>#text.scenario/block RUN (cache=miss)+ BlockContainer<P>#p1 REUSE IN-FLOW SUBTREE+ BlockContainer<P>#p2 REUSE IN-FLOW SUBTREE+ BlockContainer<P>#p4 REUSE IN-FLOW SUBTREEBlockContainer<DIV>#margins.scenario/block REUSE SUBTREEBlockContainer<DIV>#abspos-scenario.scenario/block REPLAY FRAGMENTSBlockContainer<DIV>#escaping.escaping/block REUSE SUBTREE@@ -72,6 +75,7 @@BlockContainer<DIV>#list.scenario/block REUSE SUBTREEBlockContainer<DIV>#text.scenario/block REUSE SUBTREEBlockContainer<DIV>#margins.scenario/block RUN (cache=miss)+ BlockContainer<DIV>#m3 REUSE IN-FLOW SUBTREEBlockContainer<DIV>#abspos-scenario.scenario/block REPLAY FRAGMENTSBlockContainer<DIV>#escaping.escaping/block REUSE SUBTREE`,@@ -111,6 +115,7 @@BlockContainer<DIV>#text.scenario/block REUSE SUBTREEBlockContainer<DIV>#margins.scenario/block REUSE SUBTREEBlockContainer<DIV>#abspos-scenario.scenario/block RUN (cache=miss)+ BlockContainer<DIV>#e3 REUSE IN-FLOW SUBTREEBlockContainer<DIV>#escaping.escaping/block RUN (cache=miss)`,check: equal => {diff --git a/Tests/LibWeb/Text/input/layout-run-cache-background-change-preserved.html b/Tests/LibWeb/Text/input/layout-run-cache-background-change-preserved.htmlindex 8e965316abf..aaf33a9d368 100644--- a/Tests/LibWeb/Text/input/layout-run-cache-background-change-preserved.html+++ b/Tests/LibWeb/Text/input/layout-run-cache-background-change-preserved.html@@ -60,10 +60,12 @@layout FULL@viewport/block RUN (cache=bypass)BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer<DIV>#spacer REUSE IN-FLOW SUBTREEBlockContainer<DIV>#cached/block RUN (cache=miss)layout FULL@viewport/block RUN (cache=bypass)BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer<DIV>#spacer REUSE IN-FLOW SUBTREEBlockContainer<DIV>#cached/block RUN (cache=miss)`,check: equal => {diff --git a/Tests/LibWeb/Text/input/layout-run-cache-filter-change-misses.html b/Tests/LibWeb/Text/input/layout-run-cache-filter-change-misses.htmlindex fcb7b0d4a5f..ad417ff84ca 100644--- a/Tests/LibWeb/Text/input/layout-run-cache-filter-change-misses.html+++ b/Tests/LibWeb/Text/input/layout-run-cache-filter-change-misses.html@@ -29,6 +29,7 @@@viewport/block RUN (cache=bypass)BlockContainer<HTML>/block RUN (cache=miss)BlockContainer<DIV>#cached/block RUN (cache=miss)+ BlockContainer<DIV>#inner REUSE IN-FLOW SUBTREE`,},],diff --git a/Tests/LibWeb/Text/input/layout-run-cache-flex-baseline.html b/Tests/LibWeb/Text/input/layout-run-cache-flex-baseline.htmlindex 9680ee98472..94ac8439d22 100644--- a/Tests/LibWeb/Text/input/layout-run-cache-flex-baseline.html+++ b/Tests/LibWeb/Text/input/layout-run-cache-flex-baseline.html@@ -29,7 +29,7 @@layout FULL@viewport/block RUN (cache=bypass)BlockContainer<HTML>/block RUN (cache=miss)- Box<DIV>#cached/flex REUSE SUBTREE+ BlockContainer<DIV> REUSE IN-FLOW SUBTREE`,check: equal => {const after = big.getBoundingClientRect();diff --git a/Tests/LibWeb/Text/input/layout-run-cache-inline-block-auto-height.html b/Tests/LibWeb/Text/input/layout-run-cache-inline-block-auto-height.htmlindex 47f9567544f..bef4895dae5 100644--- a/Tests/LibWeb/Text/input/layout-run-cache-inline-block-auto-height.html+++ b/Tests/LibWeb/Text/input/layout-run-cache-inline-block-auto-height.html@@ -24,7 +24,7 @@layout FULL@viewport/block RUN (cache=bypass)BlockContainer<HTML>/block RUN (cache=miss)- BlockContainer<DIV>#cached/block REUSE SUBTREE+ BlockContainer(anonymous) REUSE IN-FLOW SUBTREE`,check: equal => {const rect = cached.getBoundingClientRect();diff --git a/Tests/LibWeb/Text/input/layout-run-cache-optimization-scenarios.html b/Tests/LibWeb/Text/input/layout-run-cache-optimization-scenarios.htmlindex 181129c4bbd..285fd86d126 100644--- a/Tests/LibWeb/Text/input/layout-run-cache-optimization-scenarios.html+++ b/Tests/LibWeb/Text/input/layout-run-cache-optimization-scenarios.html@@ -60,8 +60,11 @@function movementWork(testCase) {// The single-level run exports the out-of-flow child to its caller.// Deeper chains can retain the committed subtree including that child.+ // An inline-block chain sits in an anonymous block, whose subtree is reused as it is.const replay = testCase.depth === 1 && testCase.descendant !== "inFlow";- const work = replay+ const work = testCase.format === "inlineBlock"+ ? "BlockContainer(anonymous) REUSE IN-FLOW SUBTREE"+ : replay? `${chainRun(testCase.format)} REPLAY FRAGMENTS\n BlockContainer<DIV>#target/block REUSE SUBTREE`: `${chainRun(testCase.format)} REUSE SUBTREE`;return `layout FULLdiff --git a/Tests/LibWeb/Text/input/layout-trace.html b/Tests/LibWeb/Text/input/layout-trace.htmlindex dbf36f2db40..5ee56ffe85b 100644--- a/Tests/LibWeb/Text/input/layout-trace.html+++ b/Tests/LibWeb/Text/input/layout-trace.html@@ -46,16 +46,19 @@ layoutTest({BlockContainer<HTML>/block RUN (cache=miss)BlockContainer<DIV>#target/block REUSE SUBTREEBlockContainer<DIV>#boundary/block RUN (cache=miss)+ BlockContainer<DIV>#inside REUSE IN-FLOW SUBTREElayout FULL@viewport/block RUN (cache=bypass)BlockContainer<HTML>/block RUN (cache=miss)BlockContainer<DIV>#target/block REUSE SUBTREEBlockContainer<DIV>#boundary/block RUN (cache=miss)+ BlockContainer<DIV>#inside REUSE IN-FLOW SUBTREElayout FULL@viewport/block RUN (cache=bypass)BlockContainer<HTML>/block RUN (cache=miss)BlockContainer<DIV>#target/block REUSE SUBTREEBlockContainer<DIV>#boundary/block RUN (cache=miss)+ BlockContainer<DIV>#inside REUSE IN-FLOW SUBTREE`,check: equal => {equal(target.getBoundingClientRect().top, 30, "top after flush");@@ -75,8 +78,10 @@ layoutTest({layout FULL@viewport/block RUN (cache=bypass)BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer<DIV>#spacer REUSE IN-FLOW SUBTREEBlockContainer<DIV>#target/block RUN (cache=miss)BlockContainer<DIV>#boundary/block RUN (cache=miss)+ BlockContainer<DIV>#inside REUSE IN-FLOW SUBTREElayout FULL@viewport/block RUN (cache=bypass)BlockContainer<HTML>/block RUN (cache=miss)diff --git a/Tests/LibWeb/Text/input/table-measurement-reuse-work.html b/Tests/LibWeb/Text/input/table-measurement-reuse-work.htmlindex c45d4252098..8e4e00a6518 100644--- a/Tests/LibWeb/Text/input/table-measurement-reuse-work.html+++ b/Tests/LibWeb/Text/input/table-measurement-reuse-work.html@@ -47,6 +47,7 @@Box<TABLE>#table/table RUN (cache=miss)BlockContainer<TD>#cell/block (measurement) RUN (cache=bypass)BlockContainer<TD>#cell/block RUN (cache=miss)+ BlockContainer<DIV> REUSE IN-FLOW SUBTREEBlockContainer<TD>/block REUSE SUBTREEBlockContainer<SPAN>.control/block RUN (cache=miss)`,