Files
rust_browser/crates/selectors/src/lib.rs
Zachary D. Rowitsch 826da6782e Add pre-first-paint pipeline performance optimizations
Five targeted improvements to reduce CPU time before first paint:

1. Pipeline timing instrumentation — Instant-based timing around each
   phase (HTML parse, CSS parse, style, layout, display list) logged
   via tracing::info for profiling real pages.

2. Pre-computed specificity — specificity is now calculated once during
   selector bucketing instead of on every selector-node match, reducing
   redundant work proportional to (nodes × matched rules).

3. Text measurement cache — HashMap cache in ProportionalTextMeasurer
   keyed by (text, font_size, weight, style, family) avoids redundant
   glyph measurement for repeated words with identical styling.

4. Inline fragment scanning optimization — extracted helper functions
   that use HashSet-based single-pass scanning instead of nested loops
   over active elements × line fragments on each line break.

5. Ancestor bloom filter for selector matching — counting bloom filter
   (256 u8 counters, dual FNV hashes) populated from ancestor tags,
   classes, and IDs. Selectors with descendant/child combinators check
   the filter before expensive DOM ancestor walks, skipping when
   required attributes are definitely absent.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 01:03:50 -05:00

26 lines
722 B
Rust

#![deny(unsafe_code)]
//! CSS selector parsing and matching library.
//!
//! This crate provides CSS selector functionality:
//! - `types` - Core selector types (NthExpression, Specificity, SimpleSelector, etc.)
//! - `selector` - Selector parsing and matching logic
//! - `engine` - SelectorEngine and MatchedRule for style cascade
//! - `bloom` - Counting bloom filter for ancestor attribute lookups
mod bloom;
mod engine;
mod selector;
mod types;
#[cfg(test)]
mod tests;
// Re-export all public types
pub use bloom::AncestorFilter;
pub use engine::{MatchedRule, SelectorEngine};
pub use types::{
Combinator, NthExpression, PseudoClass, PseudoElement, Selector, SelectorPart, SimpleSelector,
Specificity,
};