From fd0e2125c60506fea5408b34a0c2021b8ca7bf00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=BClker?= Date: Tue, 11 Mar 2025 00:11:20 +0100 Subject: Keep a list of slot descendants on each shadow root (#35802) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes it much faster to traverse over the slot descendants of a shadow root, which is a fairly costly part of "assign slottables to a tree". This reduces the time it takes for the results to load on wpt.fyi from over 3 minutes to about 5 seconds. Signed-off-by: Simon Wülker --- components/script/dom/node.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'components/script/dom/node.rs') diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index d4e404dc030..4a4c9f53462 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1362,7 +1362,11 @@ impl Node { // NOTE: This method traverses all descendants of the node and is potentially very // expensive. If the node is not a shadow root then assigning slottables to it won't // have any effect, so we take a fast path out. - if !self.is::() { + let Some(shadow_root) = self.downcast::() else { + return; + }; + + if !shadow_root.has_slot_descendants() { return; } -- cgit v1.2.3