LibWeb: Don't throw away UA shadow trees willy-nilly

We were unnecessarily discarding the shadow trees of various elements
when they were removed or detached from the DOM.

This especially caused a *lot* of churn when creating input elements via
setting .innerHTML on something. We ended up building each input
element's shadow tree 3 times instead of 1.

The original issue that we were trying to solve by discarding shadow
trees appears to have been solved elsewhere, and nothing else seems to
break by just allowing them to remain in place.

1.05x speedup on Speedometer's TodoMVC-jQuery.
This commit is contained in:
Andreas Kling 2025-05-09 15:35:59 +02:00 committed by Tim Flynn
commit f61df9d34c
Notes: github-actions[bot] 2025-05-09 16:50:05 +00:00
12 changed files with 0 additions and 39 deletions

View file

@ -54,12 +54,6 @@ void HTMLDetailsElement::inserted()
update_shadow_tree_slots(); update_shadow_tree_slots();
} }
void HTMLDetailsElement::removed_from(DOM::Node* old_parent, DOM::Node& old_root)
{
Base::removed_from(old_parent, old_root);
set_shadow_root(nullptr);
}
// https://html.spec.whatwg.org/multipage/interactive-elements.html#the-details-element:concept-element-attributes-change-ext // https://html.spec.whatwg.org/multipage/interactive-elements.html#the-details-element:concept-element-attributes-change-ext
void HTMLDetailsElement::attribute_changed(FlyString const& local_name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) void HTMLDetailsElement::attribute_changed(FlyString const& local_name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)
{ {

View file

@ -32,7 +32,6 @@ private:
virtual void visit_edges(Cell::Visitor&) override; virtual void visit_edges(Cell::Visitor&) override;
virtual void inserted() override; virtual void inserted() override;
virtual void removed_from(DOM::Node* old_parent, DOM::Node& old_root) override;
virtual void children_changed(ChildrenChangedMetadata const*) override; virtual void children_changed(ChildrenChangedMetadata const*) override;
virtual void attribute_changed(FlyString const& local_name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override; virtual void attribute_changed(FlyString const& local_name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;

View file

@ -1793,11 +1793,6 @@ void HTMLInputElement::form_associated_element_was_inserted()
} }
} }
void HTMLInputElement::form_associated_element_was_removed(DOM::Node*)
{
set_shadow_root(nullptr);
}
bool HTMLInputElement::is_presentational_hint(FlyString const& name) const bool HTMLInputElement::is_presentational_hint(FlyString const& name) const
{ {
if (Base::is_presentational_hint(name)) if (Base::is_presentational_hint(name))

View file

@ -192,7 +192,6 @@ public:
virtual void clear_algorithm() override; virtual void clear_algorithm() override;
virtual void form_associated_element_was_inserted() override; virtual void form_associated_element_was_inserted() override;
virtual void form_associated_element_was_removed(DOM::Node*) override;
virtual void form_associated_element_attribute_changed(FlyString const&, Optional<String> const&, Optional<FlyString> const&) override; virtual void form_associated_element_attribute_changed(FlyString const&, Optional<String> const&, Optional<FlyString> const&) override;
virtual WebIDL::ExceptionOr<void> cloned(Node&, bool) const override; virtual WebIDL::ExceptionOr<void> cloned(Node&, bool) const override;

View file

@ -175,12 +175,6 @@ void HTMLMeterElement::inserted()
create_shadow_tree_if_needed(); create_shadow_tree_if_needed();
} }
void HTMLMeterElement::removed_from(DOM::Node* old_parent, DOM::Node& old_root)
{
Base::removed_from(old_parent, old_root);
set_shadow_root(nullptr);
}
void HTMLMeterElement::adjust_computed_style(CSS::ComputedProperties& style) void HTMLMeterElement::adjust_computed_style(CSS::ComputedProperties& style)
{ {
// https://drafts.csswg.org/css-display-3/#unbox // https://drafts.csswg.org/css-display-3/#unbox

View file

@ -35,7 +35,6 @@ public:
// ^HTMLElement // ^HTMLElement
virtual void inserted() override; virtual void inserted() override;
virtual void removed_from(DOM::Node* old_parent, DOM::Node& old_root) override;
virtual void adjust_computed_style(CSS::ComputedProperties&) override; virtual void adjust_computed_style(CSS::ComputedProperties&) override;

View file

@ -96,12 +96,6 @@ void HTMLProgressElement::inserted()
create_shadow_tree_if_needed(); create_shadow_tree_if_needed();
} }
void HTMLProgressElement::removed_from(DOM::Node* old_parent, DOM::Node& old_root)
{
Base::removed_from(old_parent, old_root);
set_shadow_root(nullptr);
}
void HTMLProgressElement::adjust_computed_style(CSS::ComputedProperties& style) void HTMLProgressElement::adjust_computed_style(CSS::ComputedProperties& style)
{ {
// https://drafts.csswg.org/css-display-3/#unbox // https://drafts.csswg.org/css-display-3/#unbox

View file

@ -29,7 +29,6 @@ public:
// ^HTMLElement // ^HTMLElement
virtual void inserted() override; virtual void inserted() override;
virtual void removed_from(DOM::Node* old_parent, DOM::Node& old_root) override;
virtual void adjust_computed_style(CSS::ComputedProperties&) override; virtual void adjust_computed_style(CSS::ComputedProperties&) override;

View file

@ -574,11 +574,6 @@ void HTMLSelectElement::form_associated_element_was_inserted()
create_shadow_tree_if_needed(); create_shadow_tree_if_needed();
} }
void HTMLSelectElement::form_associated_element_was_removed(DOM::Node*)
{
set_shadow_root(nullptr);
}
void HTMLSelectElement::computed_properties_changed() void HTMLSelectElement::computed_properties_changed()
{ {
// Hide chevron icon when appearance is none // Hide chevron icon when appearance is none

View file

@ -97,7 +97,6 @@ public:
virtual void activation_behavior(DOM::Event const&) override; virtual void activation_behavior(DOM::Event const&) override;
virtual void form_associated_element_was_inserted() override; virtual void form_associated_element_was_inserted() override;
virtual void form_associated_element_was_removed(DOM::Node*) override;
void did_select_item(Optional<u32> const& id); void did_select_item(Optional<u32> const& id);

View file

@ -154,11 +154,6 @@ void HTMLTextAreaElement::form_associated_element_was_inserted()
create_shadow_tree_if_needed(); create_shadow_tree_if_needed();
} }
void HTMLTextAreaElement::form_associated_element_was_removed(DOM::Node*)
{
set_shadow_root(nullptr);
}
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-textarea-defaultvalue // https://html.spec.whatwg.org/multipage/form-elements.html#dom-textarea-defaultvalue
String HTMLTextAreaElement::default_value() const String HTMLTextAreaElement::default_value() const
{ {

View file

@ -70,7 +70,6 @@ public:
virtual WebIDL::ExceptionOr<void> cloned(Node&, bool) const override; virtual WebIDL::ExceptionOr<void> cloned(Node&, bool) const override;
virtual void form_associated_element_was_inserted() override; virtual void form_associated_element_was_inserted() override;
virtual void form_associated_element_was_removed(DOM::Node*) override;
virtual void form_associated_element_attribute_changed(FlyString const&, Optional<String> const&, Optional<FlyString> const&) override; virtual void form_associated_element_attribute_changed(FlyString const&, Optional<String> const&, Optional<FlyString> const&) override;
virtual void children_changed(ChildrenChangedMetadata const*) override; virtual void children_changed(ChildrenChangedMetadata const*) override;