Truly independent web browser
LibWeb: Build fragments in every run whose input allows them
Aliaksandr Kalenik45398442b8aa
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex c9a2acb9f6c..4d302710e10 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -32,6 +32,12 @@ enum ColumnExtent {AllRemainingContent,}+#[derive(Clone, Copy, PartialEq, Eq)]+enum ColumnLayoutUse {+ BalancingProbe,+ ContainerContent,+}+struct FragmentationState {container_content_box_block_start_in_root: CssPixels,resume: Option<fragmentation::BlockResume>,@@ -3348,7 +3354,7 @@ impl<'pass> BlockFormattingContext<'pass> {root_line_data,root,} = self.layout_column(- self.run.purpose,+ ColumnLayoutUse::ContainerContent,column_input,if is_last_allowed_column {ColumnExtent::AllRemainingContent@@ -3577,7 +3583,7 @@ impl<'pass> BlockFormattingContext<'pass> {let mut minimal_space_shortage: Option<CssPixels> = None;let finished = loop {let ColumnLayout { outcome, .. } = self.layout_column(- formatting_context::LayoutPurpose::Measurement,+ ColumnLayoutUse::BalancingProbe,column_input,ColumnExtent::BlockSize(block_size),incoming,@@ -3625,7 +3631,7 @@ impl<'pass> BlockFormattingContext<'pass> {consumed_block_size,..} = self.layout_column(- formatting_context::LayoutPurpose::Measurement,+ ColumnLayoutUse::BalancingProbe,column_input,ColumnExtent::UntilForcedBreak,incoming,@@ -3643,7 +3649,7 @@ impl<'pass> BlockFormattingContext<'pass> {fn layout_column(&self,- purpose: formatting_context::LayoutPurpose,+ column_layout_use: ColumnLayoutUse,input: LayoutInput,extent: ColumnExtent,incoming: Option<std::rc::Rc<fragmentation::BlockBreakToken>>,@@ -3662,6 +3668,10 @@ impl<'pass> BlockFormattingContext<'pass> {let mut tried_early_breaks: Vec<Node> = early_break_before.into_iter().collect();let mut minimal_space_shortage_of_discarded_attempts = None;let inline_items = self.column_inline_items.get_or_init(Default::default);+ let (purpose, builds_fragments) = match column_layout_use {+ ColumnLayoutUse::BalancingProbe => (formatting_context::LayoutPurpose::Measurement, false),+ ColumnLayoutUse::ContainerContent => (self.run.purpose, self.run.fragments.is_some()),+ };loop {let fragmentainer = std::rc::Rc::new(fragmentation::FragmentainerContext::new(block_size,@@ -3671,7 +3681,13 @@ impl<'pass> BlockFormattingContext<'pass> {early_break_before,allows_early_break_requests,));- let outputs = formatting_context::run_fragmentainer(&self.run, purpose, input, fragmentainer.clone());+ let outputs = formatting_context::run_fragmentainer(+ &self.run,+ purpose,+ builds_fragments,+ input,+ fragmentainer.clone(),+ );if outputs.result.depends_on_percentage_block_size {self.used(self.run.box_).has_descendant_that_depends_on_percentage_block_size@@ -3714,9 +3730,7 @@ impl<'pass> BlockFormattingContext<'pass> {consumed_block_size: outputs.result.automatic_content_block_size,baselines: outputs.result.baselines,root_line_data: outputs.root_outcome.line_data,- root: (purpose == formatting_context::LayoutPurpose::Commit)- .then_some(outputs.root)- .flatten(),+ root: outputs.root,};}}diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rsindex 79ba845fc5b..3759efa45fc 100644--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs@@ -15,7 +15,6 @@ use super::*;#[derive(Clone, Copy, PartialEq)]pub(super) struct FcRunCacheKey {fc_type: formatting_context::FormattingContextType,- purpose: formatting_context::LayoutPurpose,layout_mode: LayoutMode,input: LayoutInput,root_cells: used_values::RootInputCells,@@ -65,7 +64,6 @@ impl RunInputsTheStoredRunNeverObserved {impl FcRunCacheKey {pub(super) fn new(fc_type: formatting_context::FormattingContextType,- purpose: formatting_context::LayoutPurpose,layout_mode: LayoutMode,mut input: LayoutInput,root_cells: used_values::RootInputCells,@@ -76,7 +74,6 @@ impl FcRunCacheKey {}Self {fc_type,- purpose,layout_mode,input,root_cells,@@ -87,11 +84,6 @@ impl FcRunCacheKey {self.fc_type}- /// Whether the run lays out fragments, which an entry can then also stand for.- fn builds_fragments(&self) -> bool {- formatting_context::run_builds_fragments(self.purpose, self.layout_mode)- }-pub(super) fn has_no_table_cell_intrinsic_block_padding(&self) -> bool {self.input.sizing.table_cell_intrinsic_block_padding.is_none()}@@ -115,7 +107,6 @@ impl FcRunCacheKey {return false;}self.fc_type == probe.fc_type- && self.purpose == probe.purpose&& self.layout_mode == probe.layout_mode&& self.root_cells == probe.root_cells&& layout_inputs_match_ignoring_unobserved(&self.input, &probe.input, unobserved)@@ -340,6 +331,18 @@ impl FcRunCacheEntry {}}+ pub(super) fn outputs_without_fragments(&self) -> formatting_context::RunOutputs {+ formatting_context::RunOutputs {+ result: self.outputs.result,+ root: None,+ root_outcome: self.outputs.root_outcome.clone(),+ atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above: self+ .outputs+ .atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,+ host_findings: self.outputs.host_findings.clone(),+ }+ }+fn last_used_at_layout_commit(&self) -> u64 {self.last_used_at_layout_commit.load(std::sync::atomic::Ordering::Relaxed)@@ -739,13 +742,12 @@ pub(super) fn run_root_validity(callbacks: &LayoutPass<'_>, box_: Node) -> FcRun}/// A run's cache interaction, decided at probe time and concluded after-/// the run executes. Uncacheable classes bypass entirely: measurement and-/// intrinsic-sizing runs produce no fragments; subgridded grid items copy-/// the parent grid's mid-run track state, which the key cannot see;-/// anchor()-positioned roots keep their bypass while the resolved-inset-/// side effects are audited; pass entries and internal runs are not-/// spawned child runs; devtools collection emits per-run callbacks a-/// replay would skip.+/// the run executes. Uncacheable classes bypass entirely: subgridded grid+/// items copy the parent grid's mid-run track state, which the key cannot+/// see; anchor()-positioned roots keep their bypass while the resolved-inset+/// side effects are audited; pass entries, measurement roots and internal+/// runs are not spawned child runs; devtools collection emits per-run+/// callbacks a replay would skip.pub(super) enum FcRunCacheAttempt {Bypass,Store {@@ -756,7 +758,7 @@ pub(super) enum FcRunCacheAttempt {validity: FcRunCacheValidity,structurally_damaged_entry: Option<std::sync::Arc<FcRunCacheEntry>>,},- /// A run that builds no fragments, whose result is kept for its exact key.+ /// A run that builds no fragments, whose result is kept.StoreResultOnly {validity: FcRunCacheValidity,},@@ -770,45 +772,19 @@ impl FcRunCacheAttempt {}}- /// Err carries the entry the caller must replay instead of running.+ /// Err carries the entry the caller must replay instead of running. A probe whose run builds fragments takes only+ /// an entry whose run built them; any other probe reads the result of any matching entry.pub(super) fn probe(box_: Node,parent_grid_is_present: bool,- layout_mode: LayoutMode,+ builds_fragments: bool,should_collect_devtools_layout_data: bool,callbacks: &LayoutPass<'_>,key: &FcRunCacheKey,) -> Result<Self, FcRunCacheHit> {- if !key.builds_fragments() {- if !can_describe_run_in_any_layout_mode(- box_,- parent_grid_is_present,- should_collect_devtools_layout_data,- callbacks,- key,- ) {- return Ok(Self::Bypass);- }- let validity = run_root_validity(callbacks, box_);- if let Some(entry) = callbacks- .arena()- .fc_run_cache_store()- .first_entry_where(box_.slot_index(), |entry| {- entry.validity == validity && entry.outputs.root.is_none() && entry.key == *key- })- {- entry.note_used_at_layout_commit(callbacks.arena().layout_commit_count());- return Err(FcRunCacheHit {- entry,- reuses_committed_subtree: false,- });- }- return Ok(Self::StoreResultOnly { validity });- }if !can_describe_run(box_,parent_grid_is_present,- layout_mode,should_collect_devtools_layout_data,callbacks,key,@@ -817,6 +793,18 @@ impl FcRunCacheAttempt {}let store = callbacks.arena().fc_run_cache_store();let validity = run_root_validity(callbacks, box_);+ if !builds_fragments {+ if let Some(entry) = store.first_entry_where(box_.slot_index(), |entry| {+ entry.validity == validity && entry.answers_probe_for(key)+ }) {+ entry.note_used_at_layout_commit(callbacks.arena().layout_commit_count());+ return Err(FcRunCacheHit {+ entry,+ reuses_committed_subtree: false,+ });+ }+ return Ok(Self::StoreResultOnly { validity });+ }let mut reuses_committed_subtree = false;if let Some(entry) = store.first_entry_where(box_.slot_index(), |entry| {if entry.validity != validity || entry.outputs.root.is_none() || !entry.answers_probe_for(key) {@@ -927,24 +915,6 @@ impl FcRunCacheAttempt {}pub(super) fn can_describe_run(- box_: Node,- parent_grid_is_present: bool,- layout_mode: LayoutMode,- should_collect_devtools_layout_data: bool,- callbacks: &LayoutPass<'_>,- key: &FcRunCacheKey,-) -> bool {- layout_mode == LayoutMode::Normal- && can_describe_run_in_any_layout_mode(- box_,- parent_grid_is_present,- should_collect_devtools_layout_data,- callbacks,- key,- )-}--pub(super) fn can_describe_run_in_any_layout_mode(box_: Node,parent_grid_is_present: bool,should_collect_devtools_layout_data: bool,@@ -1014,7 +984,6 @@ mod tests {fn key(available_inline: AvailableSize, percentage_basis_inline_size: Option<CssPixels>) -> FcRunCacheKey {FcRunCacheKey {fc_type: formatting_context::FormattingContextType::Block,- purpose: formatting_context::LayoutPurpose::Commit,layout_mode: LayoutMode::Normal,input: LayoutInput::new(AvailableSpace {@@ -1344,7 +1313,6 @@ mod tests {let key_of = |fc_type, input| {FcRunCacheKey::new(fc_type,- formatting_context::LayoutPurpose::Commit,LayoutMode::Normal,input,used_values::RootInputCells::capture(&record),diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 8ed18c20934..c258a158970 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -124,8 +124,24 @@ impl LayoutPurpose {}}-pub(crate) fn run_builds_fragments(purpose: LayoutPurpose, layout_mode: LayoutMode) -> bool {- layout_mode == LayoutMode::Normal && !purpose.is_measurement()+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub(crate) enum RootFragments {+ WhereTheRunInputAllows,+ LeftOut,+}++pub(crate) fn run_builds_fragments(+ layout_mode: LayoutMode,+ input: &LayoutInput,+ parent_collects_fragments: bool,+) -> bool {+ // NB: An atomic inline lays its content out at the inline size it resolves from the space it is offered, which+ // MathML layout offers at max-content.+ layout_mode == LayoutMode::Normal+ && (input.participation == ParticipationInParentFormattingContext::AtomicInline+ || !input.available_space.inline_size.is_intrinsic_sizing_constraint())+ && !input.available_space.block_size.is_intrinsic_sizing_constraint()+ && (parent_collects_fragments || input.participation != ParticipationInParentFormattingContext::Root)}pub(crate) struct MeasurementState<'pass> {@@ -147,6 +163,33 @@ impl<'pass> MeasurementState<'pass> {node_used: &UsedValues,layout_mode: LayoutMode,input: LayoutInput,+ ) -> ChildLayoutResult {+ self.launch(+ RootFragments::WhereTheRunInputAllows,+ node,+ node_used,+ layout_mode,+ input,+ )+ }++ pub(crate) fn run_without_root_fragments(+ &self,+ node: Node,+ node_used: &UsedValues,+ layout_mode: LayoutMode,+ input: LayoutInput,+ ) -> ChildLayoutResult {+ self.launch(RootFragments::LeftOut, node, node_used, layout_mode, input)+ }++ fn launch(+ &self,+ root_fragments: RootFragments,+ node: Node,+ node_used: &UsedValues,+ layout_mode: LayoutMode,+ input: LayoutInput,) -> ChildLayoutResult {let fc_type = independent_formatting_context_type(node, &self.callbacks);let root_containing_block = self@@ -154,6 +197,7 @@ impl<'pass> MeasurementState<'pass> {.containing_block_for_child_run(node, &input.participation);run_formatting_context(LayoutPurpose::Measurement,+ root_fragments,None,node_used,node,@@ -177,6 +221,7 @@ impl<'pass> MeasurementState<'pass> {pub(crate) fn run_fragmentainer(outer: &FormattingContextRun,purpose: LayoutPurpose,+ builds_fragments: bool,input: LayoutInput,fragmentainer: std::rc::Rc<fragmentation::FragmentainerContext>,) -> RunOutputs {@@ -187,6 +232,7 @@ pub(crate) fn run_fragmentainer(.containing_block_for_child_run(box_, &input.participation);execute_formatting_context_run(purpose,+ builds_fragments,used_values::RootInputCells::capture(outer.records.used_values(box_)),box_,root_containing_block,@@ -1888,6 +1934,7 @@ fn body_input_with_inner_available_space(run: &FormattingContextRun, input: &Lay#[expect(clippy::too_many_arguments)]pub(super) fn run_formatting_context(purpose: LayoutPurpose,+ root_fragments: RootFragments,parent_fragments: Option<&fragment_tree::RunFragmentBuilder>,parent_used: &UsedValues,box_: Node,@@ -1906,9 +1953,16 @@ pub(super) fn run_formatting_context(parent_fragments.clear_reused_subtree_root(box_, parent_used);}let root_cells = used_values::RootInputCells::capture(parent_used);+ let builds_fragments = root_fragments == RootFragments::WhereTheRunInputAllows+ && run_builds_fragments(layout_mode, &input, parent_fragments.is_some());+ assert!(+ parent_fragments.is_none() || builds_fragments,+ "the run of {box_:?} builds no fragments for its parent to commit"+ );if callbacks.scratch().reads_no_memoized_layout() {let outputs = execute_formatting_context_run(purpose,+ builds_fragments,root_cells,box_,root_containing_block,@@ -1925,10 +1979,10 @@ pub(super) fn run_formatting_context();return absorb_run_outputs(&callbacks, parent_fragments, parent_used, box_, &input, outputs, false);}- let cache_key = fc_run_cache::FcRunCacheKey::new(fc_type, purpose, layout_mode, input, root_cells);+ let cache_key = fc_run_cache::FcRunCacheKey::new(fc_type, layout_mode, input, root_cells);let memoizes_measurement = purpose.is_measurement()&& callbacks.scratch().memoizes_measurements()- && fc_run_cache::can_describe_run_in_any_layout_mode(+ && fc_run_cache::can_describe_run(box_,parent_grid.is_some(),should_collect_devtools_layout_data,@@ -1945,7 +1999,7 @@ pub(super) fn run_formatting_context(let cache_attempt = match fc_run_cache::FcRunCacheAttempt::probe(box_,parent_grid.is_some(),- layout_mode,+ builds_fragments,should_collect_devtools_layout_data,&callbacks,&cache_key,@@ -1965,20 +2019,22 @@ pub(super) fn run_formatting_context(return result;}let reuses_committed_subtree = hit.reuses_committed_subtree;- let builds_no_fragments = hit.entry.outputs.root.is_none();+ let action = if !builds_fragments {+ "READ RESULT"+ } else if reuses_committed_subtree {+ "REUSE SUBTREE"+ } else {+ "REPLAY FRAGMENTS"+ };let _trace = callbacks.arena().layout_trace- .run(box_, fc_type, purpose, layout_mode, || {- if reuses_committed_subtree {- "REUSE SUBTREE"- } else if builds_no_fragments {- "READ RESULT"- } else {- "REPLAY FRAGMENTS"- }- });- let outputs = hit.entry.outputs_to_replay(reuses_committed_subtree);+ .run(box_, fc_type, purpose, layout_mode, || action);+ let outputs = if builds_fragments {+ hit.entry.outputs_to_replay(reuses_committed_subtree)+ } else {+ hit.entry.outputs_without_fragments()+ };return absorb_run_outputs(&callbacks,parent_fragments,@@ -1998,6 +2054,7 @@ pub(super) fn run_formatting_context(let discarded_outputs = run_repeatability::lay_out_discarded_run(&callbacks, || {execute_formatting_context_run(purpose,+ builds_fragments,root_cells,box_,root_containing_block,@@ -2015,6 +2072,7 @@ pub(super) fn run_formatting_context(});let outputs = execute_formatting_context_run(purpose,+ builds_fragments,root_cells,box_,root_containing_block,@@ -2127,6 +2185,7 @@ fn lays_out_box_for_its_content_inline_sizes(#[expect(clippy::too_many_arguments)]fn execute_formatting_context_run(purpose: LayoutPurpose,+ builds_fragments: bool,root_cells: used_values::RootInputCells,box_: Node,root_containing_block: Node,@@ -2160,7 +2219,7 @@ fn execute_formatting_context_run(treat_block_axis_percentage_insets_as_auto_beyond_root: input.sizing.treat_block_axis_percentage_insets_as_auto_beyond_root,- fragments: run_builds_fragments(purpose, layout_mode).then(|| {+ fragments: builds_fragments.then(|| {std::rc::Rc::new(fragment_tree::RunFragmentBuilder::new(box_,(!root_containing_block.is_invalid()).then_some(root_containing_block),@@ -2706,7 +2765,7 @@ pub(crate) fn layout_inside_child() -> ChildLayoutOutcome {let facts = NodeFacts::new(&run.callbacks, child);let used = run.records.used_values(child);- let child_run_builds_fragments = run_builds_fragments(run.purpose, layout_mode);+ let child_run_builds_fragments = run_builds_fragments(layout_mode, &input, run.fragments.is_some());if let Some((padding_top, padding_bottom)) = input.sizing.table_cell_intrinsic_block_padding {debug_assert!(facts.is_table_cell());debug_assert!(matches!(@@ -2742,6 +2801,7 @@ pub(crate) fn layout_inside_child(input.available_space,input.containing_block_constraints,layout_mode,+ child_run_builds_fragments,);// OPTIMIZATION: A box that took its metrics from its committed fragment is placed with that fragment, where// it shows the box as the record holds it.@@ -2809,6 +2869,7 @@ pub(crate) fn layout_inside_child(dimension_root_in_parent_scope(parent_block, child, &input, child_run_builds_fragments);let result = run_formatting_context(run.purpose,+ RootFragments::WhereTheRunInputAllows,run.fragments.as_deref(),used,child,@@ -2865,16 +2926,13 @@ pub(crate) fn run_table_cell_ahead_of_its_intrinsic_block_padding();input.sizing.flex_self_block_size_resolution_space = None;let root_cells = used_values::RootInputCells::capture(run.records.used_values(cell));- let cache_key = fc_run_cache::FcRunCacheKey::new(- FormattingContextType::Block,- LayoutPurpose::Commit,- LayoutMode::Normal,- input,- root_cells,- );+ let cache_key =+ fc_run_cache::FcRunCacheKey::new(FormattingContextType::Block, LayoutMode::Normal, input, root_cells);+ let builds_fragments = run_builds_fragments(LayoutMode::Normal, &input, false);let execute = |previous_line_data| {execute_formatting_context_run(LayoutPurpose::Commit,+ builds_fragments,root_cells,cell,root_containing_block,@@ -2894,7 +2952,6 @@ pub(crate) fn run_table_cell_ahead_of_its_intrinsic_block_padding(if !fc_run_cache::can_describe_run(cell,false,- LayoutMode::Normal,run.should_collect_devtools_layout_data,&run.callbacks,&cache_key,@@ -2906,7 +2963,7 @@ pub(crate) fn run_table_cell_ahead_of_its_intrinsic_block_padding(let cache_attempt = match fc_run_cache::FcRunCacheAttempt::probe(cell,false,- LayoutMode::Normal,+ builds_fragments,run.should_collect_devtools_layout_data,&run.callbacks,&cache_key,@@ -3290,6 +3347,7 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layolet fc_type = independent_formatting_context_type(root_for_layout, &callbacks);run_formatting_context(LayoutPurpose::Commit,+ RootFragments::WhereTheRunInputAllows,Some(&entry_fragments),root_for_layout_used,root_for_layout,@@ -3450,6 +3508,7 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {.expect("partial relayout root must establish an independent formatting context");run_formatting_context(run.purpose,+ RootFragments::WhereTheRunInputAllows,Some(fragments),root_used,root,diff --git a/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rsindex d534d839b88..dce9faf6cbc 100644--- a/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs@@ -48,6 +48,7 @@ pub(super) fn layout_replaced_with_children(let wrapper_result = formatting_context::run_formatting_context(run.purpose,+ formatting_context::RootFragments::WhereTheRunInputAllows,run.fragments.as_deref(),wrapper_state,wrapper,diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex 90e23801031..ae906b7f29e 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -1922,10 +1922,9 @@ impl<'pass> SizingContext<'pass> {available_space: AvailableSpace,constraints: ContainingBlockConstraints,layout_mode: LayoutMode,+ layout_builds_fragments: bool,) -> Option<std::sync::Arc<fragment_tree::Fragment>> {- if formatting_context::run_builds_fragments(self.purpose, layout_mode)- && let Some(fragment) = self.try_reuse_empty_atomic_root_metrics(node)- {+ if layout_builds_fragments && let Some(fragment) = self.try_reuse_empty_atomic_root_metrics(node) {return Some(fragment);}self.dimension_empty_atomic_root_fresh(node, available_space, constraints, layout_mode);diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 140a8461c90..38f5d47bb57 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -2767,7 +2767,7 @@ impl<'pass> TableFormattingContext<'pass> {.uses_collapsing_borders_model.set(used.uses_collapsing_borders_model.get());- let result = measurement.run_with_layout_mode(+ let result = measurement.run_without_root_fragments(cell.box_,&measured_root,self.run.layout_mode,diff --git a/Tests/LibWeb/Text/expected/layout-run-cache-measured-content-committed-by-replay.txt b/Tests/LibWeb/Text/expected/layout-run-cache-measured-content-committed-by-replay.txtnew file mode 100644index 00000000000..a3be49ff2b9--- /dev/null+++ b/Tests/LibWeb/Text/expected/layout-run-cache-measured-content-committed-by-replay.txt@@ -0,0 +1,4 @@+PASS: a pass that leaves the button alone (work)+PASS: another pass that leaves the button alone, after which its stored measurements age out (work)+PASS: the button measures its content anew but commits the content it laid out at its min-height before (work + checks)+PASS: the measured content is committed by replay, not by a claim it never made (work + checks)diff --git a/Tests/LibWeb/Text/expected/layout-run-cache-measurement-replay-of-recommitted-subtree-misses.txt b/Tests/LibWeb/Text/expected/layout-run-cache-measurement-replay-of-recommitted-subtree-misses.txtnew file mode 100644index 00000000000..578483045f2--- /dev/null+++ b/Tests/LibWeb/Text/expected/layout-run-cache-measurement-replay-of-recommitted-subtree-misses.txt@@ -0,0 +1,5 @@+PASS: a pass that leaves the button alone (work)+PASS: another pass that leaves the button alone, after which its stored measurements age out (work)+PASS: measuring the button reuses the inline-block committed in an earlier pass (work)+PASS: a narrower button commits the inline-block anew (work)+PASS: the stored measurement misses once the inline-block it reused was committed anew (work + checks)diff --git a/Tests/LibWeb/Text/expected/layout-run-cache-nested-reuse-under-measurement.txt b/Tests/LibWeb/Text/expected/layout-run-cache-nested-reuse-under-measurement.txtnew file mode 100644index 00000000000..4f222126aad--- /dev/null+++ b/Tests/LibWeb/Text/expected/layout-run-cache-nested-reuse-under-measurement.txt@@ -0,0 +1,2 @@+PASS: the cell's commit replays the inline-block its measurement laid out (work + checks)+PASS: a measured cell reuses its unchanged inline-block from the previous pass (work + checks)diff --git a/Tests/LibWeb/Text/input/layout-run-cache-measured-content-committed-by-replay.html b/Tests/LibWeb/Text/input/layout-run-cache-measured-content-committed-by-replay.htmlnew file mode 100644index 00000000000..8e504aebe1f--- /dev/null+++ b/Tests/LibWeb/Text/input/layout-run-cache-measured-content-committed-by-replay.html@@ -0,0 +1,105 @@+<!DOCTYPE html>+<script src="include.js"></script>+<script src="layout-test.js"></script>+<style>+ body { margin: 0; font: 20px/20px SerenitySans; }+ #container { width: 400px; }+ button { width: 180px; min-height: 200px; padding: 0; border: 0; font: inherit; }+ .marker { display: inline-block; }+</style>+<div id="container"><button id="button"><div class="marker" id="marker">some words that wrap here</div></button></div>+<div id="spacer"></div>+<script>+ const textRects = element => {+ const range = document.createRange();+ range.selectNodeContents(element);+ const origin = element.getBoundingClientRect();+ return [...range.getClientRects()].map(rect => [rect.left - origin.left, rect.top - origin.top, rect.width]);+ };+ let referenceTextRects;+ layoutTest({+ setup: async () => {+ await document.fonts.ready;+ const reference = button.cloneNode(true);+ reference.removeAttribute("id");+ reference.style.minHeight = "0px";+ document.body.appendChild(reference);+ internals.updateLayoutForTesting();+ referenceTextRects = JSON.stringify(textRects(reference.firstElementChild));+ reference.remove();+ },+ steps: [+ {+ name: "a pass that leaves the button alone",+ mutate: () => {+ spacer.style.height = "10px";+ },+ expect: `+ layout FULL+ @viewport/block RUN (cache=bypass)+ BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer<DIV>#container REUSE IN-FLOW SUBTREE+ `,+ },+ {+ name: "another pass that leaves the button alone, after which its stored measurements age out",+ mutate: () => {+ spacer.style.height = "20px";+ },+ expect: `+ layout FULL+ @viewport/block RUN (cache=bypass)+ BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer<DIV>#container REUSE IN-FLOW SUBTREE+ `,+ },+ {+ name: "the button measures its content anew but commits the content it laid out at its min-height before",+ mutate: () => {+ container.style.width = "350px";+ },+ expect: `+ layout FULL+ @viewport/block RUN (cache=bypass)+ BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer<BUTTON>#button/block RUN (cache=miss)+ BlockContainer<BUTTON>#button/block (measurement) RUN (cache=bypass)+ BlockContainer(anonymous)/flex (measurement) RUN (cache=miss)+ BlockContainer(anonymous) MEASURE max-content block (cache=hit)+ BlockContainer(anonymous) MEASURE max-content block (cache=hit)+ BlockContainer(anonymous)/block (measurement) RUN (cache=miss)+ BlockContainer<DIV>#marker.marker/block (measurement) REUSE SUBTREE+ BlockContainer(anonymous)/flex REUSE SUBTREE+ BlockContainer<DIV>#spacer REUSE IN-FLOW SUBTREE+ `,+ check: equal => {+ equal(button.getBoundingClientRect().height, 200, "button height");+ },+ },+ {+ name: "the measured content is committed by replay, not by a claim it never made",+ mutate: () => {+ button.style.minHeight = "0px";+ },+ expect: `+ layout FULL+ @viewport/block RUN (cache=bypass)+ BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer<BUTTON>#button/block RUN (cache=miss)+ BlockContainer<BUTTON>#button/block (measurement) RUN (cache=bypass)+ BlockContainer(anonymous)/flex (measurement) RUN (cache=miss)+ BlockContainer(anonymous) MEASURE max-content block (cache=hit)+ BlockContainer(anonymous) MEASURE max-content block (cache=hit)+ BlockContainer(anonymous)/block (measurement) RUN (cache=miss)+ BlockContainer<DIV>#marker.marker/block (measurement) REUSE SUBTREE+ BlockContainer(anonymous)/flex REPLAY FRAGMENTS+ BlockContainer<DIV>#spacer REUSE IN-FLOW SUBTREE+ `,+ check: equal => {+ equal(button.getBoundingClientRect().height, 40, "button height");+ equal(JSON.stringify(textRects(marker)), referenceTextRects, "inline-block text lines");+ },+ },+ ],+ });+</script>diff --git a/Tests/LibWeb/Text/input/layout-run-cache-measurement-replay-of-recommitted-subtree-misses.html b/Tests/LibWeb/Text/input/layout-run-cache-measurement-replay-of-recommitted-subtree-misses.htmlnew file mode 100644index 00000000000..211b0b44ab0--- /dev/null+++ b/Tests/LibWeb/Text/input/layout-run-cache-measurement-replay-of-recommitted-subtree-misses.html@@ -0,0 +1,134 @@+<!DOCTYPE html>+<script src="include.js"></script>+<script src="layout-test.js"></script>+<style>+ body { margin: 0; font: 20px/20px SerenitySans; }+ button { width: 180px; min-height: 200px; padding: 0; border: 0; font: inherit; }+ .marker { display: inline-block; }+</style>+<button id="button"><div class="marker" id="marker">some words that wrap here</div></button>+<div id="spacer"></div>+<script>+ const textRects = element => {+ const range = document.createRange();+ range.selectNodeContents(element);+ const origin = element.getBoundingClientRect();+ return [...range.getClientRects()].map(rect => [rect.left - origin.left, rect.top - origin.top, rect.width]);+ };+ let referenceTextRects;+ layoutTest({+ setup: async () => {+ await document.fonts.ready;+ const reference = button.cloneNode(true);+ reference.removeAttribute("id");+ reference.style.minHeight = "0px";+ document.body.appendChild(reference);+ internals.updateLayoutForTesting();+ referenceTextRects = JSON.stringify(textRects(reference.firstElementChild));+ reference.remove();+ },+ steps: [+ {+ name: "a pass that leaves the button alone",+ mutate: () => {+ spacer.style.height = "10px";+ },+ expect: `+ layout FULL+ @viewport/block RUN (cache=bypass)+ BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer(anonymous) REUSE IN-FLOW SUBTREE+ `,+ },+ {+ name: "another pass that leaves the button alone, after which its stored measurements age out",+ mutate: () => {+ spacer.style.height = "20px";+ },+ expect: `+ layout FULL+ @viewport/block RUN (cache=bypass)+ BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer(anonymous) REUSE IN-FLOW SUBTREE+ `,+ },+ {+ name: "measuring the button reuses the inline-block committed in an earlier pass",+ mutate: () => {+ button.style.minHeight = "210px";+ },+ expect: `+ layout FULL+ @viewport/block RUN (cache=bypass)+ BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer<BUTTON>#button/block RUN (cache=miss)+ BlockContainer<BUTTON>#button/block (measurement) RUN (cache=bypass)+ BlockContainer(anonymous)/flex (measurement) RUN (cache=miss)+ BlockContainer(anonymous) MEASURE max-content block (cache=hit)+ BlockContainer(anonymous) MEASURE max-content block (cache=hit)+ BlockContainer(anonymous)/block (measurement) RUN (cache=miss)+ BlockContainer<DIV>#marker.marker/block (measurement) REUSE SUBTREE+ BlockContainer(anonymous)/flex RUN (cache=miss)+ BlockContainer(anonymous) MEASURE max-content block (cache=hit)+ BlockContainer(anonymous)/block REUSE SUBTREE+ BlockContainer<DIV>#spacer REUSE IN-FLOW SUBTREE+ `,+ },+ {+ name: "a narrower button commits the inline-block anew",+ mutate: () => {+ button.style.width = "150px";+ },+ expect: `+ layout FULL+ @viewport/block RUN (cache=bypass)+ BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer<BUTTON>#button/block RUN (cache=miss)+ BlockContainer<BUTTON>#button/block (measurement) RUN (cache=bypass)+ BlockContainer(anonymous)/flex (measurement) RUN (cache=miss)+ BlockContainer(anonymous) MEASURE max-content block (cache=miss)+ BlockContainer(anonymous)/block (measurement, intrinsic) RUN (cache=bypass)+ BlockContainer<DIV>#marker.marker/block (measurement, intrinsic) RUN (cache=miss)+ BlockContainer<DIV>#marker.marker MEASURE max-content inline (cache=hit)+ BlockContainer<DIV>#marker.marker MEASURE min-content inline (cache=hit)+ BlockContainer(anonymous) MEASURE max-content block (cache=hit)+ BlockContainer(anonymous)/block (measurement) RUN (cache=miss)+ BlockContainer<DIV>#marker.marker/block (measurement) RUN (cache=miss)+ BlockContainer<DIV>#marker.marker MEASURE max-content inline (cache=hit)+ BlockContainer<DIV>#marker.marker MEASURE min-content inline (cache=hit)+ BlockContainer(anonymous)/flex RUN (cache=miss)+ BlockContainer(anonymous) MEASURE max-content block (cache=hit)+ BlockContainer(anonymous)/block RUN (cache=miss)+ BlockContainer<DIV>#marker.marker/block REPLAY FRAGMENTS+ BlockContainer<DIV>#spacer REUSE IN-FLOW SUBTREE+ `,+ },+ {+ name: "the stored measurement misses once the inline-block it reused was committed anew",+ mutate: () => {+ button.style.width = "180px";+ button.style.minHeight = "0px";+ },+ expect: `+ layout FULL+ @viewport/block RUN (cache=bypass)+ BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer<BUTTON>#button/block RUN (cache=miss)+ BlockContainer<BUTTON>#button/block (measurement) RUN (cache=bypass)+ BlockContainer(anonymous)/flex (measurement) RUN (cache=miss)+ BlockContainer(anonymous) MEASURE max-content block (cache=hit)+ BlockContainer(anonymous) MEASURE max-content block (cache=hit)+ BlockContainer(anonymous)/block (measurement) RUN (cache=miss)+ BlockContainer<DIV>#marker.marker/block (measurement) RUN (cache=miss)+ BlockContainer<DIV>#marker.marker MEASURE max-content inline (cache=hit)+ BlockContainer<DIV>#marker.marker MEASURE min-content inline (cache=hit)+ BlockContainer(anonymous)/flex REPLAY FRAGMENTS+ BlockContainer<DIV>#spacer REUSE IN-FLOW SUBTREE+ `,+ check: equal => {+ equal(JSON.stringify(textRects(marker)), referenceTextRects, "inline-block text lines");+ },+ },+ ],+ });+</script>diff --git a/Tests/LibWeb/Text/input/layout-run-cache-nested-reuse-under-measurement.html b/Tests/LibWeb/Text/input/layout-run-cache-nested-reuse-under-measurement.htmlnew file mode 100644index 00000000000..b4fa96eaf2b--- /dev/null+++ b/Tests/LibWeb/Text/input/layout-run-cache-nested-reuse-under-measurement.html@@ -0,0 +1,78 @@+<!DOCTYPE html>+<script src="include.js"></script>+<script src="layout-test.js"></script>+<style>+ body { margin: 0; }+ table { border-spacing: 0; width: 300px; }+ td { padding: 0; font: 20px/20px SerenitySans; }+ #cell { height: 100px; }+ #nested { display: inline-block; width: 80px; }+</style>+<table><tr><td id="cell"><div id="nested">some words that wrap</div></td></tr></table>+<script>+ layoutTest({+ steps: [+ {+ name: "the cell's commit replays the inline-block its measurement laid out",+ mutate: () => {+ nested.textContent = "other words that wrap";+ },+ expect: `+ layout FULL+ @viewport/block RUN (cache=bypass)+ BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer<TD>#cell MEASURE min-content inline (cache=miss) FROM ITEMS+ BlockContainer<TD>#cell MEASURE max-content inline (cache=hit)+ TableWrapper(anonymous)/block RUN (cache=miss)+ Box<TABLE>/table RUN (cache=miss)+ BlockContainer<TD>#cell MEASURE min-content inline (cache=hit)+ BlockContainer<TD>#cell MEASURE max-content inline (cache=hit)+ BlockContainer<TD>#cell MEASURE max-content block (cache=miss)+ BlockContainer<TD>#cell/block (measurement, intrinsic) RUN (cache=bypass)+ BlockContainer<DIV>#nested/block (measurement, intrinsic) RUN (cache=miss)+ BlockContainer<TD>#cell MEASURE max-content block (cache=hit)+ BlockContainer<TD>#cell MEASURE CELL (cache=miss)+ BlockContainer<TD>#cell/block (measurement) RUN (cache=miss)+ BlockContainer<DIV>#nested/block (measurement) RUN (cache=miss)+ BlockContainer<TD>#cell/block RUN (cache=miss)+ BlockContainer<DIV>#nested/block REPLAY FRAGMENTS+ `,+ check: equal => {+ equal(nested.getBoundingClientRect().width, 80, "nested width");+ },+ },+ {+ name: "a measured cell reuses its unchanged inline-block from the previous pass",+ mutate: () => {+ cell.style.height = "120px";+ },+ expect: `+ layout FULL+ @viewport/block RUN (cache=bypass)+ BlockContainer<HTML>/block RUN (cache=miss)+ BlockContainer<TD>#cell MEASURE min-content inline (cache=miss) FROM ITEMS+ BlockContainer<TD>#cell MEASURE max-content inline (cache=hit)+ TableWrapper(anonymous)/block RUN (cache=miss)+ Box<TABLE>/table RUN (cache=miss)+ BlockContainer<TD>#cell MEASURE min-content inline (cache=hit)+ BlockContainer<TD>#cell MEASURE max-content inline (cache=hit)+ BlockContainer<TD>#cell MEASURE max-content block (cache=miss)+ BlockContainer<TD>#cell/block (measurement, intrinsic) RUN (cache=bypass)+ BlockContainer<DIV>#nested/block (measurement, intrinsic) READ RESULT+ BlockContainer<TD>#cell MEASURE max-content block (cache=hit)+ BlockContainer<TD>#cell MEASURE CELL (cache=miss)+ BlockContainer<TD>#cell/block (measurement) RUN (cache=miss)+ BlockContainer<DIV>#nested/block (measurement) REUSE SUBTREE+ BlockContainer<TD>#cell/block RUN (cache=miss)+ BlockContainer<DIV>#nested/block REUSE SUBTREE+ `,+ check: equal => {+ const rect = nested.getBoundingClientRect();+ equal(rect.width, 80, "nested width");+ equal(rect.height, 80, "nested height");+ equal(cell.getBoundingClientRect().height, 120, "cell height");+ },+ },+ ],+ });+</script>