mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-10-02 03:00:23 +03:00
Optimize single-rule CSS selector matching:
Add a fast path that directly evaluates selectors containing one rule, avoiding combinator traversal and switch overhead for common class, ID, tag, and pseudo-class selectors. Move complex selector traversal into a dedicated function and cache rule counts in selector loops. Add focused matching coverage and document the Phase 7 benchmark results.
This commit is contained in:
@@ -828,6 +828,19 @@ Use instrumentation from Phase 4 to confirm:
|
||||
|
||||
# Phase 7: Add Single-Rule Selector Fast Path
|
||||
|
||||
**Status: Implemented**
|
||||
|
||||
## Implementation State
|
||||
|
||||
- `StyleSheetSelector` records whether parsing produced exactly one rule.
|
||||
- Single-rule selectors call `StyleSheetSelectorRule::matches()` directly, while selectors with
|
||||
combinators retain the existing traversal logic in `selectComplex()`.
|
||||
- A focused test covers class, ID, tag+class, and pseudo-class selectors with pseudo matching both
|
||||
enabled and disabled.
|
||||
- Across seven release benchmark runs, `Benchmark.CSSSelectorMatching` had a 93.0 ms median for
|
||||
20.48 million selector calls. Compared with the earlier Phase 5 median of approximately 111.4 ms,
|
||||
this is an indicative 16.6% reduction.
|
||||
|
||||
## Motivation
|
||||
|
||||
Many selectors are simple:
|
||||
|
||||
Reference in New Issue
Block a user