Keep a list of slot descendants on each shadow root (#35802)

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 <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-03-11 00:11:20 +01:00 committed by GitHub
parent 0419a7818d
commit fd0e2125c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 89 additions and 13 deletions

View file

@ -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::<ShadowRoot>() {
let Some(shadow_root) = self.downcast::<ShadowRoot>() else {
return;
};
if !shadow_root.has_slot_descendants() {
return;
}