LibWeb: Make "assign slottables for a tree" fast when there are no slots

We achieve this by keeping track of the number of HTMLSlotElements
inside each ShadowRoot (do via ad-hoc insertion and removal steps.)

This allows slottables assignment to skip over entire shadow roots when
we know they have no slots anyway.

Massive speedup on https://wpt.fyi/ which no longer takes minutes/hours
to load, but instead a "mere" 19 seconds. :^)
This commit is contained in:
Andreas Kling 2025-01-23 17:41:53 +01:00 committed by Andreas Kling
parent 003c045589
commit adc25af8e2
Notes: github-actions[bot] 2025-01-23 20:40:06 +00:00
4 changed files with 49 additions and 11 deletions

View file

@ -8,6 +8,7 @@
#include <LibWeb/Bindings/HTMLSlotElementPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/DOM/Text.h>
#include <LibWeb/HTML/HTMLSlotElement.h>
@ -147,4 +148,21 @@ void HTMLSlotElement::attribute_changed(FlyString const& local_name, Optional<St
}
}
void HTMLSlotElement::inserted()
{
Base::inserted();
auto& root = this->root();
if (!root.is_shadow_root())
return;
static_cast<DOM::ShadowRoot&>(root).increment_slot_count();
}
void HTMLSlotElement::removed_from(Node* old_parent, Node& old_root)
{
Base::removed_from(old_parent, old_root);
if (!old_root.is_shadow_root())
return;
static_cast<DOM::ShadowRoot&>(old_root).decrement_slot_count();
}
}