Truly independent web browser
LibWeb: Drop released intrinsic size cache entries once per layout stage
Aliaksandr Kaleniked83fb7c704d
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex dc0d2dc3759..ca6a9bade5d 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -3117,6 +3117,7 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layoarena.derive_facts_after_tree_update(&[]);}arena.mark_flex_and_grid_items_of_nodes_marked_for_layout();+ drop_intrinsic_size_cache_entries_of_released_slots(arena, scratch);let callbacks = LayoutPass::new(arena,scratch,@@ -3195,6 +3196,18 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo})}+/// Drops the intrinsic size cache entries of the slots the arena let go of, or whose cache epoch wrapped, since the+/// last stage, before any run of this one reads a cache.+fn drop_intrinsic_size_cache_entries_of_released_slots(+ arena: &LayoutNodeArena,+ scratch: &super::run_records::LayoutScratch,+) {+ let drops = arena.take_intrinsic_size_cache_drops();+ if !drops.is_empty() {+ scratch.intrinsic_size_caches.drop_slots(drops);+ }+}+fn finish_entry_pass(entry_records: &RunRecords<'_>,entry_fragments: &std::rc::Rc<fragment_tree::RunFragmentBuilder>,@@ -3247,6 +3260,7 @@ fn compute_subtree_layout_fragments(input: LayoutStageInput<'_>, containing_bloc// re-enter intrinsic sizing for descendants outside those roots, including anonymous boxes// the incremental tree build created; derive the facts of the whole subtree.arena.derive_facts_in_subtree(root);+ drop_intrinsic_size_cache_entries_of_released_slots(arena, scratch);// NB: Either way, the boundary root's own geometry lies in the frame of its containing block.let callbacks = if containing_block.is_invalid() {diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex fd14787394e..87443c0bef5 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -1474,6 +1474,10 @@ impl LayoutNodeArena {self.intrinsic_size_cache_drops.take()}+ pub(crate) fn has_intrinsic_size_cache_drops(&self) -> bool {+ !self.intrinsic_size_cache_drops.borrow().is_empty()+ }+/// What an intrinsic size cache entry measured for the row `id` now is valid for.pub(crate) fn intrinsic_size_cache_stamp(&self, id: NodeSlotId) -> IntrinsicSizeCacheStamp {IntrinsicSizeCacheStamp {diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rsindex 7d86fcdefad..4ea1bb2e1ff 100644--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs@@ -390,11 +390,10 @@ impl<'arena> RunRecords<'arena> {root_used: Option<&'arena UsedValues>,run: impl FnOnce(&Self) -> R,) -> R {- // What the arena let go of since the last run is dropped before this run reads a cache.- let drops = arena.take_intrinsic_size_cache_drops();- if !drops.is_empty() {- scratch.intrinsic_size_caches.drop_slots(drops);- }+ debug_assert!(+ !arena.has_intrinsic_size_cache_drops(),+ "the layout stage drops released intrinsic size cache entries before its runs read a cache"+ );let _innermost_run = InnermostRunGuard {arena,previous: arena.innermost_run.replace((root, root_containing_block)),