Closed Bug 2070760 Opened 2 months ago Closed 2 months ago

Use the DOM subtree filter to reject impossible selector traversals

Categories

(Core :: CSS Parsing and Computation, task)

task

Tracking

()

RESOLVED WONTFIX

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.

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.

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.

Flags: needinfo?(emilio)

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...

Flags: needinfo?(emilio)
Blocks: 2045461
Assignee: nobody → mayankleoboy1
Status: NEW → ASSIGNED

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.

Attachment #9640194 - Attachment description: WIP: Bug 2070760 - Use the DOM subtree filter to reject impossible selector traversals. r?emilio → WIP: Bug 2070760 - Prune impossible DOM descendant invalidations. r?emilio

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.

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.

Attachment #9641788 - Attachment description: WIP: Bug 2070760 - Share the DOM subtree filter helpers with selectors. r?emilio → Bug 2070760 - Share the DOM subtree filter helpers with selectors. r?emilio
Attachment #9640194 - Attachment description: WIP: Bug 2070760 - Prune impossible DOM descendant invalidations. r?emilio → Bug 2070760 - Prune impossible DOM descendant invalidations. r?emilio
Attachment #9641789 - Attachment description: WIP: Bug 2070760 - Try the DOM subtree filter during relative-selector rejection. r?emilio → Bug 2070760 - Try the DOM subtree filter during relative-selector rejection. r?emilio
Attachment #9641790 - Attachment description: WIP: Bug 2070760 - Cover DOM subtree filter rejection in selector tests. r?emilio → Bug 2070760 - Cover DOM subtree filter rejection in selector tests. r?emilio

(In reply to Mayank Bansal from comment #8)

Which test-case are you measuring here?

Flags: needinfo?(mayankleoboy1)
Pushed by ealvarez@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/bfeb8e052da7 https://hg.mozilla.org/integration/autoland/rev/940fa8ff7854 Share the DOM subtree filter helpers with selectors. r=emilio,firefox-style-system-reviewers

(In reply to Emilio Cobos Álvarez [:emilio] from comment #9)

(In reply to Mayank Bansal from comment #8)

Which test-case are you measuring here?

testcase of the blocking bug 2045461

Flags: needinfo?(mayankleoboy1)
Attachment #9640194 - Attachment description: Bug 2070760 - Prune impossible DOM descendant invalidations. r?emilio → WIP: Bug 2070760 - Prune impossible DOM descendant invalidations. r?emilio
Attachment #9641789 - Attachment description: Bug 2070760 - Try the DOM subtree filter during relative-selector rejection. r?emilio → WIP: Bug 2070760 - Try the DOM subtree filter during relative-selector rejection. r?emilio
Attachment #9641790 - Attachment description: Bug 2070760 - Cover DOM subtree filter rejection in selector tests. r?emilio → WIP: Bug 2070760 - Cover DOM subtree filter rejection in selector tests. r?emilio
Attachment #9641790 - Attachment description: WIP: Bug 2070760 - Cover DOM subtree filter rejection in selector tests. r?emilio → WIP: Bug 2070760 - Test subtree-filter negative proofs and search boundaries. r?emilio
Attachment #9640194 - Attachment description: WIP: Bug 2070760 - Prune impossible DOM descendant invalidations. r?emilio → Bug 2070760 - Prune impossible DOM descendant invalidations. r?emilio
Attachment #9641789 - Attachment description: WIP: Bug 2070760 - Try the DOM subtree filter during relative-selector rejection. r?emilio → Bug 2070760 - Try the DOM subtree filter during relative-selector rejection. r?emilio
Attachment #9641790 - Attachment description: WIP: Bug 2070760 - Test subtree-filter negative proofs and search boundaries. r?emilio → Bug 2070760 - Test subtree-filter negative proofs and search boundaries. r?emilio
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → WONTFIX
Attachment #9641790 - Attachment is obsolete: true
Attachment #9641789 - Attachment is obsolete: true
Attachment #9640194 - Attachment is obsolete: true

Curious, why abandoning these? Not opposed necessarily, and it allows us to focus on your patches with Sp3 impact, but just curious.

I will not be taking these patches forward, there is no clear benefit, and no sp3 impact. So closing it.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: