ladybird/Libraries/LibWeb/DOM
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
..
AbortController.cpp LibWeb: Only set prototype once for object with IDL interface 2025-04-20 18:43:11 +02:00
AbortController.h LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
AbortController.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
AbortSignal.cpp LibJS+LibWeb: Port interned bytecode strings to UTF-16 2025-08-14 10:27:08 +02:00
AbortSignal.h LibWeb: Support removing callbacks from AbortSignal 2025-04-11 12:10:46 -04:00
AbortSignal.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
AbstractElement.cpp LibWeb: Add StyleScope to keep style caches per Document/ShadowRoot 2025-11-14 22:05:33 +01:00
AbstractElement.h LibWeb: Add StyleScope to keep style caches per Document/ShadowRoot 2025-11-14 22:05:33 +01:00
AbstractRange.cpp LibWeb: Only set prototype once for object with IDL interface 2025-04-20 18:43:11 +02:00
AbstractRange.h LibWeb: Only clear command states and values if range actually changed 2025-01-24 23:53:26 +01:00
AbstractRange.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
AccessibilityTreeNode.cpp LibWeb/DOM: Set missing JSON attributes for a11y text nodes 2025-10-20 10:51:19 +01:00
AccessibilityTreeNode.h LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
AdoptedStyleSheets.cpp LibWeb: Add StyleScope to keep style caches per Document/ShadowRoot 2025-11-14 22:05:33 +01:00
AdoptedStyleSheets.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
Attr.cpp LibWeb: Remove unnecessary lowercase name property from Attr 2025-11-10 22:55:38 +01:00
Attr.h LibWeb: Remove unnecessary lowercase name property from Attr 2025-11-10 22:55:38 +01:00
Attr.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
CDATASection.cpp LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
CDATASection.h LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
CDATASection.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
CharacterData.cpp LibWeb: Some text-related cleanup 2025-09-12 15:34:09 -04:00
CharacterData.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
CharacterData.idl LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
ChildNode.h LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
ChildNode.idl LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
Comment.cpp LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
Comment.h LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
Comment.idl LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
CustomEvent.cpp LibWeb: Only set prototype once for object with IDL interface 2025-04-20 18:43:11 +02:00
CustomEvent.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
CustomEvent.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Document.cpp LibWeb: Add StyleScope to keep style caches per Document/ShadowRoot 2025-11-14 22:05:33 +01:00
Document.h LibWeb: Add StyleScope to keep style caches per Document/ShadowRoot 2025-11-14 22:05:33 +01:00
Document.idl LibWeb: Amend Document interface to make it compatible with TrustedTypes 2025-10-27 16:14:20 +00:00
DocumentFragment.cpp LibWeb: Only set prototype once for object with IDL interface 2025-04-20 18:43:11 +02:00
DocumentFragment.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
DocumentFragment.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
DocumentLoadEventDelayer.cpp LibWeb: Allow moving document load event delayers 2025-05-22 17:44:40 -04:00
DocumentLoadEventDelayer.h LibWeb: Allow moving document load event delayers 2025-05-22 17:44:40 -04:00
DocumentLoading.cpp LibWeb: Avoid invoking Trusted Types where avoidable 2025-11-06 11:43:06 -05:00
DocumentLoading.h Everywhere: Clean up AD-HOC and FIXME comments without colons 2025-11-13 15:56:04 +01:00
DocumentObserver.cpp LibWeb/DOM: Support changing document to observe in DocumentObserver 2025-06-24 09:56:14 +02:00
DocumentObserver.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
DocumentOrShadowRoot.h LibWeb: Correctly sort animations returned by getAnimations() 2025-11-10 18:29:07 +01:00
DocumentOrShadowRoot.idl LibWeb: Add activeElement attribute in ShadowRoot 2025-09-10 16:52:39 +01:00
DocumentType.cpp LibWeb: Update DOMImplementation.createDocumentType() name validation 2025-06-19 07:55:47 -04:00
DocumentType.h LibWeb: Update DOMImplementation.createDocumentType() name validation 2025-06-19 07:55:47 -04:00
DocumentType.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
DOMEventListener.cpp LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
DOMEventListener.h LibWeb: Correctly implement event listeners default passive attribute 2024-12-25 14:57:22 +00:00
DOMImplementation.cpp LibJS+LibWeb: Port interned bytecode strings to UTF-16 2025-08-14 10:27:08 +02:00
DOMImplementation.h LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
DOMImplementation.idl LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
DOMTokenList.cpp LibWeb: Avoid invoking Trusted Types where avoidable 2025-11-06 11:43:06 -05:00
DOMTokenList.h LibWeb: Improve relList feature detection support 2024-12-06 18:09:53 +00:00
DOMTokenList.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
EditingHostManager.cpp LibWeb: Implement up/down arrow navigation for EditingHostManager 2025-09-18 07:39:10 -04:00
EditingHostManager.h LibWeb: Do not update selection on uneditable contents without Shift key 2025-08-26 10:25:59 +02:00
Element.cpp LibWeb: Allow all elements with tabindex attribute to be focusable 2025-11-12 13:57:05 +01:00
Element.h LibWeb: Allow all elements with tabindex attribute to be focusable 2025-11-12 13:57:05 +01:00
Element.idl LibWeb: Avoid invoking Trusted Types where avoidable 2025-11-06 11:43:06 -05:00
ElementByIdMap.cpp LibJS+LibWeb: Use GC::Weak instead of AK::WeakPtr for GC-allocated types 2025-10-17 17:22:16 +02:00
ElementByIdMap.h LibJS+LibWeb: Use GC::Weak instead of AK::WeakPtr for GC-allocated types 2025-10-17 17:22:16 +02:00
ElementFactory.cpp LibWeb: Add SVGFEFunc{A,B,G,R}Element 2025-11-09 01:22:48 +01:00
ElementFactory.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
Event.cpp LibWeb: Make Event.currentTarget return WindowProxy instead of Window 2025-10-15 15:36:34 +02:00
Event.h LibWeb: Make Event.currentTarget return WindowProxy instead of Window 2025-10-15 15:36:34 +02:00
Event.idl LibWeb: Make Event.currentTarget return WindowProxy instead of Window 2025-10-15 15:36:34 +02:00
EventDispatcher.cpp LibWeb: Make Event.currentTarget return WindowProxy instead of Window 2025-10-15 15:36:34 +02:00
EventDispatcher.h LibWeb: Implement legacyOutputDidListenersThrowFlag 2024-11-26 14:50:27 +01:00
EventHandler.idl LibWeb: Implement the Gamepad API with SDL3 2025-09-01 21:10:47 +02:00
EventTarget.cpp LibJS: Have JS::Lexer take a JS::SourceCode as input 2025-11-09 12:14:03 +01:00
EventTarget.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
EventTarget.idl LibWeb: Correctly implement event listeners default passive attribute 2024-12-25 14:57:22 +00:00
HTMLCollection.cpp Meta: Enforce newlines around namespaces 2025-05-14 02:01:59 -06:00
HTMLCollection.h LibGC: Rename MarkedVector => RootVector 2024-12-26 19:10:44 +01:00
HTMLCollection.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
IDLEventListener.cpp LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
IDLEventListener.h LibWeb: Correctly implement event listeners default passive attribute 2024-12-25 14:57:22 +00:00
InputEventsTarget.h LibWeb: Implement up/down arrow navigation in textarea 2025-08-15 06:32:11 -04:00
LiveNodeList.cpp LibGC: Rename MarkedVector => RootVector 2024-12-26 19:10:44 +01:00
LiveNodeList.h LibGC: Rename MarkedVector => RootVector 2024-12-26 19:10:44 +01:00
MutationObserver.cpp LibJS+LibWeb: Use GC::Weak instead of AK::WeakPtr for GC-allocated types 2025-10-17 17:22:16 +02:00
MutationObserver.h LibJS+LibWeb: Use GC::Weak instead of AK::WeakPtr for GC-allocated types 2025-10-17 17:22:16 +02:00
MutationObserver.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
MutationRecord.cpp LibWeb: Only set prototype once for object with IDL interface 2025-04-20 18:43:11 +02:00
MutationRecord.h LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
MutationRecord.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
MutationType.cpp LibWeb: Remove the initialize_strings methods 2025-01-12 00:35:58 +01:00
MutationType.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
NamedNodeMap.cpp LibWeb: Implement TrustedTypes spec for set_value on Attribute 2025-10-27 16:14:20 +00:00
NamedNodeMap.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
NamedNodeMap.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Node.cpp LibWeb: Add StyleScope to keep style caches per Document/ShadowRoot 2025-11-14 22:05:33 +01:00
Node.h LibWeb: Amend Element interface to make it compatible with TrustedTypes 2025-10-27 16:14:20 +00:00
Node.idl LibWeb: Port node text content to UTF-16 2025-07-28 18:30:50 +02:00
NodeFilter.cpp LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
NodeFilter.h LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
NodeFilter.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
NodeIterator.cpp LibJS+LibWeb: Port interned bytecode strings to UTF-16 2025-08-14 10:27:08 +02:00
NodeIterator.h LibWeb: Return actual callback object from NodeIterator::filter 2025-02-24 18:29:03 +01:00
NodeIterator.idl LibWeb: Return actual callback object from NodeIterator::filter 2025-02-24 18:29:03 +01:00
NodeList.cpp LibWeb: Only set prototype once for object with IDL interface 2025-04-20 18:43:11 +02:00
NodeList.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
NodeList.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
NodeOperations.cpp LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
NodeOperations.h LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
NodeType.h LibWeb: Move DOM::NodeType to its own file 2025-02-19 08:45:51 -05:00
NonDocumentTypeChildNode.h AK+Everywhere: Rename verify_cast to as 2025-01-21 11:34:06 -05:00
ParentNode.cpp Everywhere: Change west consts caught by clang-format-21 to east consts 2025-08-29 18:18:55 +01:00
ParentNode.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
ParentNode.idl LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
Position.cpp LibWeb: Make DOM::Position's node mandatory 2025-08-20 12:25:00 +01:00
Position.h LibWeb: Make DOM::Position's node mandatory 2025-08-20 12:25:00 +01:00
ProcessingInstruction.cpp LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
ProcessingInstruction.h LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
ProcessingInstruction.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
PseudoElement.cpp LibWeb: Support counter-* properties on pseudo-elements 2025-06-19 12:35:31 +01:00
PseudoElement.h LibWeb: Store custom properties in an OrderedHashMap 2025-09-18 14:59:14 +02:00
QualifiedName.cpp LibWeb: Make sure we run selectors for mixed-case tag names 2025-07-09 14:36:08 +02:00
QualifiedName.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
Range.cpp LibWeb: Make Trusted Types injection sink names more readable 2025-11-06 11:43:06 -05:00
Range.h LibWeb: Hook TrustedTypes to the Range Dom api 2025-10-13 13:22:01 +01:00
Range.idl LibWeb: Hook TrustedTypes to the Range Dom api 2025-10-13 13:22:01 +01:00
SelectionchangeEventDispatching.h Everywhere: Clean up AD-HOC and FIXME comments without colons 2025-11-13 15:56:04 +01:00
ShadowRoot.cpp LibWeb: Add StyleScope to keep style caches per Document/ShadowRoot 2025-11-14 22:05:33 +01:00
ShadowRoot.h LibWeb: Add StyleScope to keep style caches per Document/ShadowRoot 2025-11-14 22:05:33 +01:00
ShadowRoot.idl LibWeb: Amend ShadowRoot to make it compatible with TrustedTypes 2025-10-27 16:14:20 +00:00
Slot.cpp Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Slot.h Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Slottable.cpp LibWeb: Replace usages of dynamic_cast with as and as_if 2025-08-22 20:26:09 +02:00
Slottable.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
Slottable.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
StaticNodeList.cpp LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
StaticNodeList.h LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
StaticRange.cpp LibJS+LibWeb: Port interned bytecode strings to UTF-16 2025-08-14 10:27:08 +02:00
StaticRange.h LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
StaticRange.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
StyleElementUtils.cpp LibWeb: Port node text content to UTF-16 2025-07-28 18:30:50 +02:00
StyleElementUtils.h LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
StyleInvalidator.cpp LibWeb: Invalidate less elements affected by CSS custom properties 2025-07-30 11:06:05 +02:00
StyleInvalidator.h LibWeb: Invalidate less elements affected by CSS custom properties 2025-07-30 11:06:05 +02:00
Text.cpp LibJS+LibWeb: Port interned bytecode strings to UTF-16 2025-08-14 10:27:08 +02:00
Text.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
Text.idl LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16 2025-07-24 19:00:20 +02:00
TreeWalker.cpp LibJS+LibWeb: Port interned bytecode strings to UTF-16 2025-08-14 10:27:08 +02:00
TreeWalker.h LibWeb: Return actual callback object from TreeWalker::filter 2025-02-24 18:29:03 +01:00
TreeWalker.idl LibWeb: Return actual callback object from TreeWalker::filter 2025-02-24 18:29:03 +01:00
Utils.cpp AK+Everywhere: Rename verify_cast to as 2025-01-21 11:34:06 -05:00
Utils.h Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
XMLDocument.cpp LibWeb: Only set prototype once for object with IDL interface 2025-04-20 18:43:11 +02:00
XMLDocument.h Everywhere: Use URL::about_XXX factory functions 2025-02-15 17:05:55 +00:00
XMLDocument.idl Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00