Skip to content

Commit 92044a6

Browse files
committed
css: optimize CssPropertyCache - replace BTreeMaps with sorted Vecs
Major performance optimization (~34% faster StyledDom::create) by converting CssPropertyCache from BTreeMap-heavy to sorted Vec storage with binary search lookups: - Remove CssDependencyChain and dependency_chains field entirely - Convert user_overridden_properties: BTreeMap to sorted Vec - Convert computed_values: BTreeMap to sorted Vec - Remove resolved_cache field, use compact_cache.tier3_overflow instead - Sort css_props/cascaded_props by (state, prop_type) for binary search - Replace O(n^2) apply_ua_css with bitset-based approach - Add PartialOrd/Ord to PseudoStateType for sorted stateful properties - Rewrite get_element_font_size to use computed_values (fix recursion) - Update compact_cache_builder to populate tier3_overflow Benchmark: StyledDom::create 9.3s to 6.2s on deserialize.rs test case.
1 parent d90cf10 commit 92044a6

6 files changed

Lines changed: 302 additions & 632 deletions

File tree

core/src/compact_cache_builder.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::prop_cache::CssPropertyCache;
99
use crate::styled_dom::StyledNodeState;
1010
use azul_css::compact_cache::*;
1111
use azul_css::css::CssPropertyValue;
12+
use azul_css::props::property::{CssProperty, CssPropertyType};
1213
use azul_css::props::basic::length::SizeMetric;
1314
use azul_css::props::layout::dimensions::{LayoutHeight, LayoutWidth};
1415
use azul_css::props::layout::flex::LayoutFlexBasis;
@@ -23,9 +24,14 @@ impl CssPropertyCache {
2324
/// Resolves all layout-relevant properties for every node in the "normal" state
2425
/// (no hover/active/focus) and encodes them into compact arrays.
2526
///
26-
/// For the initial layout pass (where all nodes are in normal state), this provides
27-
/// O(1) array-indexed access to all properties instead of BTreeMap lookups.
28-
pub fn build_compact_cache(&self, node_data: &[NodeData]) -> CompactLayoutCache {
27+
/// `resolved_props` is the pre-resolved property cache (from `build_resolved_cache()`).
28+
/// All resolved properties are stored in `tier3_overflow` for generic property access,
29+
/// while tier1/2/2b provide fast-path access for layout-hot properties.
30+
pub fn build_compact_cache(
31+
&self,
32+
node_data: &[NodeData],
33+
resolved_props: Vec<Vec<(CssPropertyType, CssProperty)>>,
34+
) -> CompactLayoutCache {
2935
let node_count = self.node_count;
3036
let default_state = StyledNodeState::default();
3137
let mut result = CompactLayoutCache::with_capacity(node_count);
@@ -384,6 +390,18 @@ impl CssPropertyCache {
384390
}
385391
}
386392

393+
// =====================================================================
394+
// Tier 3: Populate overflow with ALL resolved properties
395+
// =====================================================================
396+
// This serves as the generic property store for get_property() lookups.
397+
// Properties already encoded in tier1/2/2b are also stored here so that
398+
// get_property() can return CssProperty references for any property type.
399+
for (i, props) in resolved_props.into_iter().enumerate() {
400+
if !props.is_empty() {
401+
result.tier3_overflow[i] = Some(Box::new(props));
402+
}
403+
}
404+
387405
result
388406
}
389407
}

0 commit comments

Comments
 (0)