Skip to content

Truly independent web browser

LibWeb: Skip the list counter reconcile after a whole-tree build

Andreas Kling19e651072182
diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
index 852d2a53e94..6d48e2ae6de 100644
--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
@@ -1449,6 +1449,8 @@ pub(crate) struct TreeBuildAnswer {
pub(crate) reports: Vec<crate::layout::commit::FfiCommitMessage>,
/// The scroll containers the build gave a style.
pub(crate) built_scroll_containers: Vec<super::formatting_context::FfiBuiltScrollContainer>,
+ /// Whether the build built the whole tree again, rather than only the subtrees it was asked to.
+ pub(crate) rebuilt_whole_tree: bool,
}
impl TreeBuildAnswer {
@@ -1513,10 +1515,13 @@ impl TreeBuildJob {
);
let document_layout_node = host.arena().layout_root();
+ // NB: A build that escaped its rebuild roots still skipped every clean subtree, so it did not build the
+ // whole tree again.
+ let rebuilt_whole_tree = !document_layout_node.is_invalid()
+ && (context.document_needs_full_layout_tree_update || !document_had_layout_node);
let rebuilt_subtrees_were_updated_individually = !document_layout_node.is_invalid()
- && !(context.document_needs_full_layout_tree_update
- || !document_had_layout_node
- || state.layout_tree_update_escaped_rebuild_roots);
+ && !rebuilt_whole_tree
+ && !state.layout_tree_update_escaped_rebuild_roots;
if !document_layout_node.is_invalid() {
if rebuilt_subtrees_were_updated_individually {
fixup_tables_in_rebuilt_subtrees(
@@ -1620,6 +1625,7 @@ impl TreeBuildJob {
outcome,
reports: state.reports,
built_scroll_containers,
+ rebuilt_whole_tree,
}
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/update_layout.rs b/Libraries/LibWeb/Rust/src/layout/update_layout.rs
index a9e8d80f6b2..e68850d79a1 100644
--- a/Libraries/LibWeb/Rust/src/layout/update_layout.rs
+++ b/Libraries/LibWeb/Rust/src/layout/update_layout.rs
@@ -886,9 +886,9 @@ impl LayoutRoundJob {
answer
}
- /// Runs `build`, records it, and answers how the round goes on from it. A build that shows the value of a
- /// `list-item` counter, while some list's counters are stale, may show a stale one: the document reconciles them
- /// with what was built before anything is laid out.
+ /// Runs `build`, records it, and answers how the round goes on from it. A build of some subtrees that shows the
+ /// value of a `list-item` counter, while some list's counters are stale, may show a stale one: the document
+ /// reconciles them with what was built before anything is laid out.
fn build(
state: &mut ArenaHandle,
build: TreeBuildJob,
@@ -899,12 +899,21 @@ impl LayoutRoundJob {
let replaced_viewport = state.arena().layout_root();
let built = build.run(state, work);
state.arena_mut().record_layout_tree_build(&built.outcome);
+ // A build of the whole tree resolves every counter again, so no counter it shows is stale, and the document
+ // is the root it rebuilt.
if has_stale_list_item_counters {
- answer.rebuilt_roots = state.arena().pending_rebuilt_dom_roots();
+ answer.rebuilt_roots = if built.rebuilt_whole_tree {
+ vec![crate::painting::host::FfiNodeIdentity {
+ style_node: 0,
+ is_document: true,
+ }]
+ } else {
+ state.arena().pending_rebuilt_dom_roots()
+ };
}
let end = if built.outcome.needs_another_build_pass {
BuildEnd::AnotherPass
- } else if has_stale_list_item_counters && built.shows_list_item_counter_value() {
+ } else if has_stale_list_item_counters && !built.rebuilt_whole_tree && built.shows_list_item_counter_value() {
BuildEnd::ReconcileCounters
} else {
BuildEnd::LayOut