Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
perf(style): accept proven zero-match invalidations
ldm0ae83a56624e0
diff --git a/moli-renderer-v8/src/style_engine/request.rs b/moli-renderer-v8/src/style_engine/request.rsindex 09343f579..04d7c8349 100644--- a/moli-renderer-v8/src/style_engine/request.rs+++ b/moli-renderer-v8/src/style_engine/request.rs@@ -110,6 +110,17 @@ impl RetainedSourceDependencyRequestPlan {}impl RetainedSourceDependencyRequestContext<'_> {+ /// Whether an active source reporting zero matching dependencies proves+ /// that this request has no style effect.+ ///+ /// Direct keyed attribute/class/id mutations have enough source-local+ /// dependency information for that proof. Structural, relative, state,+ /// and slot requests keep their safety roots because a zero match can also+ /// mean that the retained query did not cover the mutation boundary.+ pub(super) fn zero_matched_dependency_result_is_exact(&self) -> bool {+ matches!(self, Self::Attribute)+ }+fn dependency_fallback_context(&self,query: &RetainedStyleInvalidationQuery,diff --git a/moli-renderer-v8/src/style_engine/retained_plan.rs b/moli-renderer-v8/src/style_engine/retained_plan.rsindex f3fd0779c..2933e6129 100644--- a/moli-renderer-v8/src/style_engine/retained_plan.rs+++ b/moli-renderer-v8/src/style_engine/retained_plan.rs@@ -191,6 +191,13 @@ impl RetainedBaseQueryPlan {cause_fallback,&mut target_queries,);+ let zero_matched_dependency_result_is_exact =+ request_context.zero_matched_dependency_result_is_exact();+ for target_query in &mut target_queries {+ target_query.set_zero_matched_dependency_result_is_exact(+ zero_matched_dependency_result_is_exact,+ );+ }target_queries}diff --git a/moli-renderer-v8/src/style_engine/target_queries.rs b/moli-renderer-v8/src/style_engine/target_queries.rsindex 7f0a0abef..8da2e219b 100644--- a/moli-renderer-v8/src/style_engine/target_queries.rs+++ b/moli-renderer-v8/src/style_engine/target_queries.rs@@ -33,6 +33,7 @@ pub(super) struct PendingRetainedSourceStyleInvalidationInput<'a> {kind: StyloRetainedSourceStyleInvalidationKind,fallback_kind: Option<StyloRetainedSourceStyleInvalidationKind>,retained_queries: Option<&'a IndexSet<RetainedStyleInvalidationQuery>>,+ zero_matched_dependency_result_is_exact: bool,reasoned_fallback_roots: &'a IndexSet<DomHandle>,exact_safety_fallback_roots: &'a IndexSet<DomHandle>,fallback_reasons: &'a IndexSet<StyloSourceInvalidationFallbackReason>,@@ -80,6 +81,7 @@ struct PendingStyleInvalidationTargetPayload {retained_source_kind: StyloRetainedSourceStyleInvalidationKind,fallback_kind: Option<StyloRetainedSourceStyleInvalidationKind>,retained_queries: Option<IndexSet<RetainedStyleInvalidationQuery>>,+ zero_matched_dependency_result_is_exact: bool,fallback_root_buckets: PendingStyleInvalidationFallbackRootBuckets,}@@ -327,6 +329,18 @@ impl PendingStyleInvalidationTargetQueries {self.context.set_mutation_snapshot(snapshot);}+ pub(super) fn set_zero_matched_dependency_result_is_exact(&mut self, is_exact: bool) {+ // A light-tree keyed mutation can affect a shadow stylesheet through+ // :host, :host-context, ::slotted, or a relative selector even when+ // that source's local cascade reports no direct dependency match.+ // Keep cross-tree sources conservative until Stylo exposes a stronger+ // per-source proof for those relationships.+ let source_scope_is_document =+ matches!(self.context.target.scope_id(), StyleScopeId::Document(_));+ self.payload+ .set_zero_matched_dependency_result_is_exact(is_exact && source_scope_is_document);+ }+pub(super) fn extend_structural_boundary_cleanup_roots(&mut self,roots: impl IntoIterator<Item = DomHandle>,@@ -365,6 +379,9 @@ impl PendingStyleInvalidationTargetQueries {kind: self.retained_source_invalidation_kind(),fallback_kind: self.payload.fallback_kind(),retained_queries: self.retained_queries(),+ zero_matched_dependency_result_is_exact: self+ .payload+ .zero_matched_dependency_result_is_exact(),reasoned_fallback_roots: self.reasoned_fallback_root_set(),exact_safety_fallback_roots: self.exact_safety_fallback_root_set(),fallback_reasons: self.fallback_reasons(),@@ -715,6 +732,7 @@ impl<'a> PendingRetainedSourceStyleInvalidationInput<'a> {cascade_data,self.shadow_root(),self.retained_queries,+ self.zero_matched_dependency_result_is_exact,self.reasoned_fallback_roots,self.exact_safety_fallback_roots,self.fallback_reasons,@@ -779,6 +797,7 @@ impl PendingStyleInvalidationTargetPayload {retained_source_kind: StyloRetainedSourceStyleInvalidationKind::RetainedQueries,fallback_kind: None,retained_queries: Some(queries),+ zero_matched_dependency_result_is_exact: false,fallback_root_buckets: PendingStyleInvalidationFallbackRootBuckets::default(),}}@@ -795,6 +814,7 @@ impl PendingStyleInvalidationTargetPayload {retained_source_kind,fallback_kind: Some(retained_source_kind),retained_queries: None,+ zero_matched_dependency_result_is_exact: false,fallback_root_buckets: PendingStyleInvalidationFallbackRootBuckets::with_reasoned(roots,),@@ -806,6 +826,7 @@ impl PendingStyleInvalidationTargetPayload {retained_source_kind: StyloRetainedSourceStyleInvalidationKind::MissingFallbackRoots,fallback_kind: Some(StyloRetainedSourceStyleInvalidationKind::MissingFallbackRoots),retained_queries: None,+ zero_matched_dependency_result_is_exact: false,fallback_root_buckets: PendingStyleInvalidationFallbackRootBuckets::default(),}}@@ -822,6 +843,10 @@ impl PendingStyleInvalidationTargetPayload {self.retained_queries.as_ref()}+ fn zero_matched_dependency_result_is_exact(&self) -> bool {+ self.zero_matched_dependency_result_is_exact && self.fallback_kind.is_none()+ }+fn reasoned_fallback_roots(&self) -> &IndexSet<DomHandle> {self.fallback_root_buckets.reasoned_roots()}@@ -852,7 +877,13 @@ impl PendingStyleInvalidationTargetPayload {);}+ fn set_zero_matched_dependency_result_is_exact(&mut self, is_exact: bool) {+ self.zero_matched_dependency_result_is_exact = is_exact && self.retained_queries.is_some();+ }+fn merge_from(&mut self, incoming: Self) {+ self.zero_matched_dependency_result_is_exact &=+ incoming.zero_matched_dependency_result_is_exact;if let Some(incoming_queries) = incoming.retained_queries {self.retained_queries.get_or_insert_with(IndexSet::new)diff --git a/moli-renderer-v8/src/style_engine/tests/dependency.rs b/moli-renderer-v8/src/style_engine/tests/dependency.rsindex a9d6929d0..696b11e71 100644--- a/moli-renderer-v8/src/style_engine/tests/dependency.rs+++ b/moli-renderer-v8/src/style_engine/tests/dependency.rs@@ -75,6 +75,72 @@ fn pending_target_query_merge_preserves_all_fallback_reasons() {.contains(&StyloSourceInvalidationFallbackReason::UnsupportedStateDependency));}++#[test]+fn zero_matched_dependency_exactness_requires_document_scope_and_survives_only_safe_merges() {+ let mut host = test_host();+ let document = host.document_handle();+ let shadow_host = host.create_element("section");+ assert!(host.append_child(document, shadow_host));+ let shadow_root = host+ .attach_shadow_root(shadow_host, "open")+ .expect("test host should accept a shadow root");+ let query = RetainedStyleInvalidationQuery::class(document, "inactive".into());++ let document_source = StyleSourceId::document_adopted_style_sheet(document, 1);+ let mut document_target = PendingStyleInvalidationTargetQueries::retained_source(+ document_source.clone(),+ indexmap::IndexSet::from([query.clone()]),+ );+ document_target.set_zero_matched_dependency_result_is_exact(true);+ let document_input = retained_source_input_for_test(+ document_target+ .retained_source_invalidation_input()+ .into_stylo_input(None),+ );+ assert_eq!(+ document_input.zero_matched_dependency_result_is_exact,+ Some(true)+ );++ let shadow_source = StyleSourceId::shadow_root_adopted_style_sheet(shadow_root, 2);+ let mut shadow_target = PendingStyleInvalidationTargetQueries::retained_source(+ shadow_source,+ indexmap::IndexSet::from([query.clone()]),+ );+ shadow_target.set_zero_matched_dependency_result_is_exact(true);+ let shadow_input = retained_source_input_for_test(+ shadow_target+ .retained_source_invalidation_input()+ .into_stylo_input(None),+ );+ assert_eq!(+ shadow_input.zero_matched_dependency_result_is_exact,+ Some(false)+ );++ let mut safe_target = PendingStyleInvalidationTargetQueries::retained_source(+ document_source.clone(),+ indexmap::IndexSet::from([query.clone()]),+ );+ safe_target.set_zero_matched_dependency_result_is_exact(true);+ let mut unsafe_target = PendingStyleInvalidationTargetQueries::retained_source(+ document_source,+ indexmap::IndexSet::from([query]),+ );+ unsafe_target.set_zero_matched_dependency_result_is_exact(false);+ let mut merged = vec![safe_target];+ super::target_queries::merge_pending_target_queries(&mut merged, vec![unsafe_target]);+ let merged_input = retained_source_input_for_test(+ merged[0]+ .retained_source_invalidation_input()+ .into_stylo_input(None),+ );+ assert_eq!(+ merged_input.zero_matched_dependency_result_is_exact,+ Some(false)+ );+}#[test]fn missing_source_roots_fallback_preserves_dependency_reason_and_missing_roots() {let host = test_host();diff --git a/moli-renderer-v8/src/style_engine/tests/invalidator.rs b/moli-renderer-v8/src/style_engine/tests/invalidator.rsindex 4ea6372fd..ce2acc137 100644--- a/moli-renderer-v8/src/style_engine/tests/invalidator.rs+++ b/moli-renderer-v8/src/style_engine/tests/invalidator.rs@@ -3158,6 +3158,88 @@ fn retained_stylo_invalidator_uses_snapshots_for_mixed_attribute_state_batches());assert!(engine.computed_style_cache_contains_handle_for_document_for_test(document, unrelated));}+#[test]+fn retained_stylo_invalidator_accepts_inactive_media_dependency_as_exact_empty() {+ let mut host = test_host();+ let document = host.document_handle();+ let source = host.create_element("div");+ let target = host.create_element("span");+ let unrelated = host.create_element("aside");++ assert!(host.set_attribute(target, "class", "target"));+ assert!(host.set_attribute(unrelated, "id", "unrelated"));+ assert!(host.append_child(document, source));+ assert!(host.append_child(document, target));+ assert!(host.append_child(document, unrelated));++ let mut engine = MoliStyleEngine::new();+ let document_url = url::Url::parse("https://example.test/").unwrap();+ let stylesheet = StyloStylesheetSource::new(+ "@media print {+ .probe + .target { color: red; }+ }+ #unrelated { color: rgb(1, 2, 3); }"+ .into(),+ document_url.clone(),+ );+ engine.set_document_adopted_style_sheet_sources(document, vec![stylesheet.clone()]);+ let mut inputs = FullStyleWorldSnapshot::default();+ inputs.document_stylesheet_sources.push(stylesheet);++ assert_eq!(+ engine.computed_style_property_value(+ &host,+ &document_url,+ target,+ "color",+ None,+ &inputs,+ None,+ ),+ Some("rgb(0, 0, 0)".into())+ );+ assert_eq!(+ engine.computed_style_property_value(+ &host,+ &document_url,+ unrelated,+ "color",+ None,+ &inputs,+ None,+ ),+ Some("rgb(1, 2, 3)".into())+ );++ assert!(host.set_attribute(source, "class", "probe"));+ engine.invalidate_for_mutations(+ &host,+ &[StyleMutationEffect::Attribute {+ element: source,+ name: "class".into(),+ old_value: None,+ new_value: Some("probe".into()),+ }],+ &crate::protocol_types::EmulatedMediaOverrides::default(),+ );+ engine.drain_pending_style_invalidations_for_document_for_test(&host, document);++ assert!(engine.computed_style_cache_contains_handle_for_document_for_test(document, target));+ assert!(engine.computed_style_cache_contains_handle_for_document_for_test(document, unrelated));+ assert_eq!(+ engine.computed_style_property_value(+ &host,+ &document_url,+ target,+ "color",+ None,+ &inputs,+ None,+ ),+ Some("rgb(0, 0, 0)".into())+ );+}+#[test]fn retained_stylo_invalidator_narrows_target_sibling_cache_invalidation() {let mut host = test_host();diff --git a/moli-renderer-v8/src/style_engine/tests/mod.rs b/moli-renderer-v8/src/style_engine/tests/mod.rsindex 27d5013b6..55c550530 100644--- a/moli-renderer-v8/src/style_engine/tests/mod.rs+++ b/moli-renderer-v8/src/style_engine/tests/mod.rs@@ -84,6 +84,7 @@ struct PlannedSourceDependencyInputForTest {struct RetainedSourceInputForTest {fallback_kind: Option<StyloRetainedSourceStyleInvalidationKind>,retained_fallback_kind: Option<Option<StyloRetainedSourceStyleInvalidationKind>>,+ zero_matched_dependency_result_is_exact: Option<bool>,}impl StyloPlannedFallbackRootInvalidationTargetPartsSink<DomHandle>@@ -230,12 +231,15 @@ impl<'a> StyloRetainedSourceStyleInvalidationSink<'a, DomHandle, MoliMutationSna_cascade_data: Option<&'a ServoArc<CascadeData>>,_shadow_root: Option<DomHandle>,_queries: &'a indexmap::IndexSet<RetainedStyleInvalidationQuery>,+ zero_matched_dependency_result_is_exact: bool,_reasoned_fallback_roots: &'a indexmap::IndexSet<DomHandle>,_exact_safety_fallback_roots: &'a indexmap::IndexSet<DomHandle>,_fallback_reasons: &'a indexmap::IndexSet<StyloSourceInvalidationFallbackReason>,_mutation_snapshot: &'a MoliMutationSnapshot,) {self.retained_fallback_kind = Some(fallback_kind);+ self.zero_matched_dependency_result_is_exact =+ Some(zero_matched_dependency_result_is_exact);}fn run_fallback_source_style_invalidation(@@ -472,6 +476,7 @@ fn collect_source_invalidation_roots_for_test(.as_ref().expect("retained source test input should carry queries"),),+ false,&planned.reasoned_fallback_roots,&planned.exact_safety_fallback_roots,&planned.fallback_reasons,@@ -490,6 +495,7 @@ fn collect_source_invalidation_roots_for_test(None,None,None,+ false,&planned.reasoned_fallback_roots,&planned.exact_safety_fallback_roots,&planned.fallback_reasons,diff --git a/moli-selector/src/stylo/invalidation.rs b/moli-selector/src/stylo/invalidation.rsindex 40e7a7087..8cf762ee8 100644--- a/moli-selector/src/stylo/invalidation.rs+++ b/moli-selector/src/stylo/invalidation.rs@@ -768,8 +768,8 @@ pub fn stylo_source_invalidation_fallback_reason_plan(StyloSourceInvalidationFallbackReason::InexactEmptyResult => {StyloSourceInvalidationFallbackReasonPlan {owner: "Stylo source query result exactness",- missing_fact: "proof that an empty source query result is an exact no-op",- next_work_item: "mark exact empty results separately from inexact zero-root results",+ missing_fact: "complete verification for a matched dependency branch that returned no affected roots",+ next_work_item: "extend snapshot and relative-dependency verification; direct keyed document-scope zero matches are already exact",}}StyloSourceInvalidationFallbackReason::MissingFallbackRoots => {@@ -1801,6 +1801,7 @@ impl StyleDomHostBinding<'_> {stylist: &Stylist,queries: &IndexSet<StyloRetainedStyleInvalidationQuery>,exact_safety_fallback_roots: &IndexSet<NodeId>,+ zero_matched_dependency_result_is_exact: bool,snapshots: &[StyloStyleInvalidationSnapshot],) -> StyloSourceStyleInvalidationResult {let mut accumulated = StyloSourceStyleInvalidationResultAccumulator::new();@@ -1819,7 +1820,10 @@ impl StyleDomHostBinding<'_> {);accumulated.merge_invalidation_query_result(result);}- accumulated.into_source_result(exact_safety_fallback_roots)+ accumulated.into_source_result_with_zero_matched_dependency_exactness(+ exact_safety_fallback_roots,+ zero_matched_dependency_result_is_exact,+ )}/// Collect roots for a retained source-aware invalidation batch.@@ -1885,6 +1889,7 @@ impl<'a, 'binding, 'dom_binding, 'host, 'stylist, 'result>cascade_data: Option<&'a ServoArc<CascadeData>>,shadow_root: Option<NodeId>,queries: &'a IndexSet<StyloRetainedStyleInvalidationQuery>,+ zero_matched_dependency_result_is_exact: bool,reasoned_fallback_roots: &'a IndexSet<NodeId>,exact_safety_fallback_roots: &'a IndexSet<NodeId>,fallback_reasons: &'a IndexSet<StyloSourceInvalidationFallbackReason>,@@ -1923,6 +1928,7 @@ impl<'a, 'binding, 'dom_binding, 'host, 'stylist, 'result>stylist,queries,exact_safety_fallback_roots,+ zero_matched_dependency_result_is_exact,&snapshots,);self.result.push_source_result_from_planned_fallback(@@ -2228,6 +2234,7 @@ mod tests {struct RetainedSourceInputPartsForTest {retained_fallback_kind: Option<Option<StyloRetainedSourceStyleInvalidationKind>>,retained_query_count: usize,+ retained_zero_matched_dependency_result_is_exact: Option<bool>,retained_reasoned_fallback_roots: Vec<NodeId>,retained_exact_safety_fallback_roots: Vec<NodeId>,retained_fallback_reasons: Vec<StyloSourceInvalidationFallbackReason>,@@ -2245,6 +2252,7 @@ mod tests {_cascade_data: Option<&'a ServoArc<CascadeData>>,_shadow_root: Option<NodeId>,queries: &'a IndexSet<StyloRetainedStyleInvalidationQuery>,+ zero_matched_dependency_result_is_exact: bool,reasoned_fallback_roots: &'a IndexSet<NodeId>,exact_safety_fallback_roots: &'a IndexSet<NodeId>,fallback_reasons: &'a IndexSet<StyloSourceInvalidationFallbackReason>,@@ -2252,6 +2260,8 @@ mod tests {) {self.retained_fallback_kind = Some(fallback_kind);self.retained_query_count = queries.len();+ self.retained_zero_matched_dependency_result_is_exact =+ Some(zero_matched_dependency_result_is_exact);self.retained_reasoned_fallback_roots.extend(reasoned_fallback_roots.iter().copied());self.retained_exact_safety_fallback_roots@@ -3423,6 +3433,7 @@ mod tests {None,None,Some(&queries),+ true,&reasoned_fallback_roots,&exact_safety_fallback_roots,&fallback_reasons,@@ -3436,6 +3447,10 @@ mod tests {)));assert_eq!(retained.retained_query_count, 1);+ assert_eq!(+ retained.retained_zero_matched_dependency_result_is_exact,+ Some(true)+ );assert_eq!(retained.retained_reasoned_fallback_roots, vec![root]);assert!(retained.retained_exact_safety_fallback_roots.is_empty());assert_eq!(@@ -3449,6 +3464,7 @@ mod tests {None,None,None,+ false,&reasoned_fallback_roots,&exact_safety_fallback_roots,&fallback_reasons,@@ -3629,6 +3645,7 @@ mod tests {None,None,None,+ false,&first_fallback_roots,&exact_safety_fallback_roots,&first_fallback_reasons,@@ -3640,6 +3657,7 @@ mod tests {None,None,None,+ false,&second_fallback_roots,&exact_safety_fallback_roots,&second_fallback_reasons,