Truly independent web browser
LibWeb: Send slot assignments to the style engine once per batch
Tim Ledbettera98a03616b09
diff --git a/Libraries/LibWeb/CSS/StyleEngineInput.cpp b/Libraries/LibWeb/CSS/StyleEngineInput.cppindex fb237b4d477..d0408ed0ea6 100644--- a/Libraries/LibWeb/CSS/StyleEngineInput.cpp+++ b/Libraries/LibWeb/CSS/StyleEngineInput.cpp@@ -63,7 +63,7 @@ static void record_element_heading_level(DOM::Element&);static void record_element_initial_features(DOM::Element&);static void record_element_inline_style_properties(DOM::Element&);static void record_heading_levels_in_subtree(DOM::Element&);-static void republish_assigned_slot_of(DOM::Node&);+static void republish_assigned_slots_of(ReadonlySpan<GC::Ref<DOM::Node>>);static Optional<StyleEngineFFI::FfiStateFact> state_fact_for(PseudoClass);static StyleAtomID intern_id_or_class_atom(StyleEngine&, DOM::Element const&, Utf16FlyString const&);static u32 element_construction_facts(DOM::Element const&);@@ -552,8 +552,7 @@ static void record_subtree_arrivals(DOM::Document& document, ReadonlySpan<GC::Reappend_dom_order_link(links, node);StyleEngineFFI::style_engine_link_style_nodes_in_dom_order(style_engine.host(), links.span());- for (auto const& node : dom_order_arrivals)- republish_assigned_slot_of(node);+ republish_assigned_slots_of(dom_order_arrivals);// What the insertion steps publish about a node under its identity waited for the identity (see Node::inserted()).auto focused_area = document.focused_area();@@ -1311,14 +1310,24 @@ void record_top_layer_changed(DOM::Document& document)// Assignment runs inside the insertion that connects a node, which happens before the subtree it arrived in is named,// and the list published then names only the members that already had an identity. Both ends of the relation therefore// republish on arrival: a slottable the list it has just become a member of, and a slot the list it arrived owning.-static void republish_assigned_slot_of(DOM::Node& node)+static void republish_assigned_slots_of(ReadonlySpan<GC::Ref<DOM::Node>> nodes){- if (auto slot = DOM::assigned_slot_for_node(node)) {- slot->assign_slottables_if_needed();- record_slot_assignment_changed(*slot);+ Vector<GC::Ref<HTML::HTMLSlotElement>> slots;+ HashTable<HTML::HTMLSlotElement const*> seen_slots;+ auto add_slot = [&](HTML::HTMLSlotElement& slot) {+ if (seen_slots.set(&slot) == HashSetResult::InsertedNewEntry)+ slots.append(slot);+ };+ for (auto const& node : nodes) {+ if (auto slot = DOM::assigned_slot_for_node(node)) {+ slot->assign_slottables_if_needed();+ add_slot(*slot);+ }+ if (auto* slot = as_if<HTML::HTMLSlotElement>(*node))+ add_slot(*slot);}- if (auto* slot = as_if<HTML::HTMLSlotElement>(node))- record_slot_assignment_changed(*slot);+ for (auto const& slot : slots)+ record_slot_assignment_changed(slot);}static void record_element_disconnecting(DOM::Element& element, TreeScopeID tree_scope)diff --git a/Libraries/LibWeb/Rust/src/css/style/inputs.rs b/Libraries/LibWeb/Rust/src/css/style/inputs.rsindex 66ec029e102..4d2a445b23f 100644--- a/Libraries/LibWeb/Rust/src/css/style/inputs.rs+++ b/Libraries/LibWeb/Rust/src/css/style/inputs.rs@@ -1079,6 +1079,7 @@ impl RetainedState {/// Replace the ordered list of nodes a slot has assigned to it, text nodes included.pub fn set_slot_assigned_nodes(&mut self, slot: StyleNodeID, nodes: &[StyleNodeID]) {+ self.counters.bump(Counter::SlotAssignedNodeListsPublished);self.tree.set_assigned_nodes(slot, nodes, &mut self.memory);}diff --git a/Libraries/LibWeb/Rust/src/css/style/instrumentation.rs b/Libraries/LibWeb/Rust/src/css/style/instrumentation.rsindex 47f3ab65a61..fea66cff4dd 100644--- a/Libraries/LibWeb/Rust/src/css/style/instrumentation.rs+++ b/Libraries/LibWeb/Rust/src/css/style/instrumentation.rs@@ -64,6 +64,7 @@ define_counters! {StyleAtomsReclaimed => "styleAtomsReclaimed",LanguageTextsPublished => "languageTextsPublished",CustomPropertyNamesPublished => "customPropertyNamesPublished",+ SlotAssignedNodeListsPublished => "slotAssignedNodeListsPublished",// Exclusive transaction intervals. Fused stages retain one name until execution splits.TransactionMicroseconds => "transactionMicroseconds",diff --git a/Tests/LibWeb/Text/expected/css/style-engine/slot-assigned-nodes-published-once-per-arrival.txt b/Tests/LibWeb/Text/expected/css/style-engine/slot-assigned-nodes-published-once-per-arrival.txtnew file mode 100644index 00000000000..1d40582c852--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/style-engine/slot-assigned-nodes-published-once-per-arrival.txt@@ -0,0 +1 @@+slot lists published: 2diff --git a/Tests/LibWeb/Text/input/css/style-engine/slot-assigned-nodes-published-once-per-arrival.html b/Tests/LibWeb/Text/input/css/style-engine/slot-assigned-nodes-published-once-per-arrival.htmlnew file mode 100644index 00000000000..15a0da82898--- /dev/null+++ b/Tests/LibWeb/Text/input/css/style-engine/slot-assigned-nodes-published-once-per-arrival.html@@ -0,0 +1,15 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<div id="host"></div>+<script>+ test(() => {+ host.attachShadow({ mode: "open" }).innerHTML = "<slot></slot>";+ internals.updateStyle();+ const before = internals.styleEngineCounters().slotAssignedNodeListsPublished;+ for (let i = 0; i < 20; ++i)+ host.append(" ", document.createElement("span"));+ internals.updateStyle();+ const after = internals.styleEngineCounters().slotAssignedNodeListsPublished;+ println(`slot lists published: ${after - before}`);+ });+</script>