Skip to content

Truly independent web browser

LibWeb: Reuse selector matches of elements whose declarations change

Tim Ledbetter64d89f1611f1
diff --git a/Libraries/LibWeb/Rust/src/css/style/flush.rs b/Libraries/LibWeb/Rust/src/css/style/flush.rs
index d3e6e27f767..ecf381c9fa1 100644
--- a/Libraries/LibWeb/Rust/src/css/style/flush.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/flush.rs
@@ -1521,7 +1521,8 @@ impl StyleEngine {
refreshes,
}
} else if !node_deltas.is_empty()
- || (patch.always_emit_for(node) && patch.rule_keys.is_empty())
+ || patch.always_emit_nodes.binary_search(&node).is_ok()
+ || (patch.always_emit && patch.rule_keys.is_empty())
|| !patch.cascade_update_properties.is_empty()
{
SelectorTruthPatch::Direct(node_deltas)
diff --git a/Libraries/LibWeb/Rust/src/css/style/routing.rs b/Libraries/LibWeb/Rust/src/css/style/routing.rs
index b0aab4b116b..790146f0c25 100644
--- a/Libraries/LibWeb/Rust/src/css/style/routing.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/routing.rs
@@ -111,7 +111,6 @@ impl RetainedState {
// A declaration sourced from the element changes what wins on that element and nothing
// else. There is no selector to transpose: the region is the element itself.
if let InputKey::ElementDeclaration(node, _) = input.key {
- self.record_selector_truth_refresh(node, None);
regions.add(ImpactRegion::Node(node));
return;
}
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/element-declarations-beside-tree-change.txt b/Tests/LibWeb/Text/expected/css/style-engine/element-declarations-beside-tree-change.txt
new file mode 100644
index 00000000000..e3f5451230f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/style-engine/element-declarations-beside-tree-change.txt
@@ -0,0 +1,3 @@
+selector truth repair upqueries: 1
+candidate checks: 7
+rect height: 60px
diff --git a/Tests/LibWeb/Text/input/css/style-engine/element-declarations-beside-tree-change.html b/Tests/LibWeb/Text/input/css/style-engine/element-declarations-beside-tree-change.html
new file mode 100644
index 00000000000..7a1bdbed28c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/style-engine/element-declarations-beside-tree-change.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<svg width="200" height="100"><g id="bars"></g><g id="churn"><line></line><line></line></g></svg>
+<script>
+ test(() => {
+ const namespace = "http://www.w3.org/2000/svg";
+ const bars = document.getElementById("bars");
+ const churn = document.getElementById("churn");
+ const rects = [];
+ for (let index = 0; index < 50; ++index) {
+ const rect = document.createElementNS(namespace, "rect");
+ rect.setAttribute("width", 2);
+ rect.setAttribute("height", 50);
+ bars.appendChild(rect);
+ rects.push(rect);
+ }
+ internals.updateStyle();
+
+ const before = internals.styleEngineCounters();
+ for (const rect of rects)
+ rect.setAttribute("height", 60);
+ churn.firstElementChild.remove();
+ churn.appendChild(document.createElementNS(namespace, "line"));
+ internals.updateStyle();
+ const after = internals.styleEngineCounters();
+ println(`selector truth repair upqueries: ${after.selectorTruthRepairUpqueries - before.selectorTruthRepairUpqueries}`);
+ println(`candidate checks: ${after.candidateChecks - before.candidateChecks}`);
+ println(`rect height: ${getComputedStyle(rects[0]).height}`);
+ });
+</script>