Use the DOM subtree filter to reject impossible selector traversals
Categories
(Core :: CSS Parsing and Computation, task)
Tracking
()
People
(Reporter: mayankleoboy1, Assigned: mayankleoboy1)
References
(Blocks 1 open bug)
Details
Attachments
(1 external file, 3 obsolete files)
Bug 1997380 added a filter to each element that summarizes the local names, classes, and null-namespace attribute names in its DOM subtree. It is currently used to skip subtrees during selector queries.
Use that existing filter as a shared conservative rejection mechanism for two additional selector traversals:
- relative-selector matching, as proposed in bug 2005808; and
- descendant style invalidation, motivated by the workload in bug 2045461.
Compute mandatory hashes for the relevant selector compound, preserving quirks-mode behavior and omitting constraints the DOM filter cannot represent. Keep the existing DOM filter propagation unchanged so selector-query selectivity is not reduced. Only prune invalidation traversals where the filter is known to cover the complete search space, with conservative fallbacks for shadow trees and other composed-tree traversal.
Add unit tests for hash extraction and web-platform tests covering mixed invalidations, sibling selectors, attribute changes, quirks mode, and shadow boundaries.
This bug tracks the shared mechanism and its two consumers. Whether it fully resolves the performance problem in bug 2045461 depends on benchmark results.
| Assignee | ||
Comment 1•2 months ago
|
||
Share the existing DOM subtree hash representation and precompute mandatory
compound masks. Use those masks to reject relative-selector searches when
matching does not need to record selector flags.
Prune individual descendant invalidations while preserving pending sibling
work. Resolve quirks mode when constructing each invalidation and recompute
the mask when advancing to another compound.
Keep DOM filter propagation unchanged to preserve existing query selectivity.
Enable snapshot invalidation filtering only for document-tree elements when
the composed document has no shadow roots; other traversal contexts retain
the conservative fallback unless they traverse only the light tree.
Add selector-hash unit tests and WPT coverage for mixed dependencies,
siblings, attribute changes, quirks mode, and shadow boundaries.
| Assignee | ||
Comment 2•2 months ago
|
||
| Assignee | ||
Comment 3•2 months ago
|
||
Emilio what do you think of the approach, and the patch? Only Linux shows a 0.6% improvement.
This patch is quite conservative and deoptimizes shadow-tree for correctness as a first attempt.
Comment 4•2 months ago
|
||
That's not surprising because even an <input> element or a <select> has a shadow root? So the code is effectively dead I assume, since all the TodoMVC tests have a text input.
Regarding the patch:
- Why do we even need the shadow dom stuff?
- The quirks mode can't change so why is it moved around with the
Invalidations?
Other than that it's not unreasonable but...
Updated•2 months ago
|
| Assignee | ||
Comment 5•2 months ago
|
||
Move the filter accessors from TElement to selectors::Element and extract
the hash conversion into selectors::subtree_filter. Update the existing
DOM query callers without changing the filter representation, propagation,
or query behavior.
Updated•2 months ago
|
| Assignee | ||
Comment 6•2 months ago
|
||
Integrate the cheap DOM filter check into RelativeSelectorFilterMap so it
shares traversal-root selection and negative-result caching with the
existing rejection path. Skip the new check when matching needs to record
selector flags for later :has() invalidation.
Keep the wider filter for IDs, namespaces, collisions, and child-only
searches. Record DOM rejections as lookups so unresolved later selectors
can build the wider filter without another warm-up traversal. Precompute
subject masks and refresh them when replacing nesting parents.
| Assignee | ||
Comment 7•2 months ago
|
||
Add mask unit tests for compound offsets, quirks mode, unsupported
constraints, and nested selectors. Cover invalidation across mixed
dependencies, compound advancement, attribute changes, form controls,
shadow hosts, slots, exported parts, host scopes, and placeholder rendering.
Exercise relative queries in descendant and sibling search spaces,
including ID alternatives, child-only boundaries, nested selectors, and
style invalidation after a negative :has() query.
| Assignee | ||
Comment 8•2 months ago
•
|
||
- fastpath (0 attribute): https://share.firefox.dev/3Vujxhl (134ms)
- slowpath (heavy attributes): https://share.firefox.dev/3SI1bsv (200ms)
- sp3 perf: https://perf.compare/compare-results?baseRev=b16b809a6656eb9c360cea29786d29094173fdee&baseRepo=try&newRev=01f56742acc18b848c697230894d8b5b040d968c&newRepo=try&framework=13&sort=median-diff%7Casc&initialized=1
- try opt: https://treeherder.mozilla.org/jobs?repo=try&revision=880a609a110a748175384212f38e710d56073b8e
- try debug: https://treeherder.mozilla.org/jobs?repo=try&revision=ca38d70ac193a85a3962e265da94d09bf832415e
- Nightly: fastpath/slowpath: https://share.firefox.dev/3URGdrI (21seconds)
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Comment 9•2 months ago
|
||
(In reply to Mayank Bansal from comment #8)
- fastpath (0 attribute): https://share.firefox.dev/3Vujxhl (134ms)
Which test-case are you measuring here?
Comment 10•2 months ago
|
||
| Assignee | ||
Comment 11•2 months ago
|
||
(In reply to Emilio Cobos Álvarez [:emilio] from comment #9)
(In reply to Mayank Bansal from comment #8)
- fastpath (0 attribute): https://share.firefox.dev/3Vujxhl (134ms)
Which test-case are you measuring here?
testcase of the blocking bug 2045461
Comment 12•2 months ago
|
||
| bugherder | ||
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
| Assignee | ||
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Comment 13•2 months ago
|
||
Curious, why abandoning these? Not opposed necessarily, and it allows us to focus on your patches with Sp3 impact, but just curious.
| Assignee | ||
Comment 14•2 months ago
|
||
I will not be taking these patches forward, there is no clear benefit, and no sp3 impact. So closing it.
Description
•