ladybird/Libraries/LibWeb/Page
Andreas Kling 66263f142b LibWeb: Add StyleScope to keep style caches per Document/ShadowRoot
Before this change, we've been maintaining various StyleComputer caches
at the document level.

This made sense for old-school documents without shadow trees, since
all the style information was document-wide anyway. However, documents
with many shadow trees ended up suffering since any time you mutated
a style sheet inside a shadow tree, *all* style caches for the entire
document would get invalidated.

This was particularly expensive on Reddit, which has tons of shadow
trees with their own style elements. Every time we'd create one of their
custom elements, we'd invalidate the document-level "rule cache" and
have to rebuild it, taking about ~60ms each time (ouch).

This commit introduces a new object called StyleScope.

Every Document and ShadowRoot has its own StyleScope. Rule caches etc
are moved from StyleComputer to StyleScope.

Rule cache invalidation now happens at StyleScope level. As an example,
rule cache rebuilds now take ~1ms on Reddit instead of ~60ms.

This is largely a mechanical change, moving things around, but there's
one key detail to be aware of: due to the :host selector, which works
across the shadow DOM boundary and reaches from inside a shadow tree out
into the light tree, there are various places where we have to check
both the shadow tree's StyleScope *and* the document-level StyleScope
in order to get all rules that may apply.
2025-11-14 22:05:33 +01:00
..
DragAndDropEventHandler.cpp LibWeb+LibGfx: Apply editorial punctuation/whitespace/markup fixes 2025-06-25 03:12:19 +12:00
DragAndDropEventHandler.h LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
EventHandler.cpp LibWeb: Avoid invoking Trusted Types where avoidable 2025-11-06 11:43:06 -05:00
EventHandler.h LibJS+LibWeb: Use GC::Weak instead of AK::WeakPtr for GC-allocated types 2025-10-17 17:22:16 +02:00
EventResult.h Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
InputEvent.cpp LibWeb+UI+WebContent: Pipe pinch events from AppKit UI to WebContent 2025-10-10 15:37:45 +02:00
InputEvent.h LibWeb+UI+WebContent: Pipe pinch events from AppKit UI to WebContent 2025-10-10 15:37:45 +02:00
Page.cpp LibWeb: Add StyleScope to keep style caches per Document/ShadowRoot 2025-11-14 22:05:33 +01:00
Page.h LibWeb: Avoid invoking Trusted Types where avoidable 2025-11-06 11:43:06 -05:00