Skip to content

Truly independent web browser

LibWeb: Build a transaction's topology only when it is wide enough

Andreas Klingfc4c83d5f08d
diff --git a/Libraries/LibWeb/Rust/src/css/style/flush.rs b/Libraries/LibWeb/Rust/src/css/style/flush.rs
index c7759fb39d4..10b3024836b 100644
--- a/Libraries/LibWeb/Rust/src/css/style/flush.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/flush.rs
@@ -649,20 +649,21 @@ impl StyleEngine {
return false;
}
- // A normalized transaction this wide will ask enough tree-shaped questions to amortize one
- // preorder pass. Keep the coordinates in Tier-4 scratch and let smaller updates continue to
- // walk the mandatory relation columns directly.
- const TRANSACTION_TOPOLOGY_MINIMUM_INPUTS: usize = 32;
- let mut regions = if transaction.inputs.len() >= TRANSACTION_TOPOLOGY_MINIMUM_INPUTS {
- let regions = ImpactRegions::with_topology(&self.retained.tree, root);
- let bytes = regions.topology_capacity_bytes();
- self.retained
- .memory
- .reserve_required(MemoryCategory::BatchScratch, bytes);
- regions
- } else {
- ImpactRegions::new()
- };
+ // A preorder pass takes a step per element of the document, where a tree-shaped question
+ // walks the mandatory relation columns along a node's ancestors, and a transaction asks a
+ // few of them per input. A transaction this wide against its document amortizes the pass.
+ // Keep the coordinates in Tier-4 scratch and let narrower updates walk the columns.
+ let mut regions =
+ if transaction.inputs.len().saturating_mul(16) >= self.retained.tree.connected_element_count() as usize {
+ let regions = ImpactRegions::with_topology(&self.retained.tree, root);
+ let bytes = regions.topology_capacity_bytes();
+ self.retained
+ .memory
+ .reserve_required(MemoryCategory::BatchScratch, bytes);
+ regions
+ } else {
+ ImpactRegions::new()
+ };
let topology_bytes = regions.topology_capacity_bytes();
let mut arriving_nodes: Vec<StyleNodeID> = if !transaction.has_coarsened_markers() {
transaction
diff --git a/Libraries/LibWeb/Rust/src/css/style/tests.rs b/Libraries/LibWeb/Rust/src/css/style/tests.rs
index fd94b1b6017..e84c5107d16 100644
--- a/Libraries/LibWeb/Rust/src/css/style/tests.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/tests.rs
@@ -9297,7 +9297,7 @@ fn the_same_type_arriving_routes_an_of_type_position() {
let mut planned = Vec::new();
assert!(engine.take_style_transaction_nodes(nodes[0], |nodes| planned.extend_from_slice(nodes)));
- assert_eq!(planned, vec![nodes[3].raw(), inserted.raw()]);
+ assert_eq!(planned, vec![inserted.raw(), nodes[3].raw()]);
}
#[test]
@@ -9355,7 +9355,7 @@ fn an_arrival_with_no_type_facts_keeps_of_type_routing_conservative() {
let mut planned = Vec::new();
assert!(engine.take_style_transaction_nodes(nodes[0], |nodes| planned.extend_from_slice(nodes)));
- assert_eq!(planned, vec![nodes[3].raw(), inserted.raw()]);
+ assert_eq!(planned, vec![inserted.raw(), nodes[3].raw()]);
}
fn nth_target_document() -> (StyleEngine, Vec<StyleNodeID>) {
@@ -9397,7 +9397,7 @@ fn an_arrival_routes_only_an_plus_b_positions_that_can_flip() {
let mut planned = Vec::new();
assert!(engine.take_style_transaction_nodes(nodes[0], |nodes| planned.extend_from_slice(nodes)));
- assert_eq!(planned, vec![nodes[2].raw(), nodes[3].raw(), inserted.raw()]);
+ assert_eq!(planned, vec![inserted.raw(), nodes[2].raw(), nodes[3].raw()]);
}
#[test]