Skip to content

Truly independent web browser

LibWeb: Remove style engine paths only the memory policy could reach

Andreas Kling30a20ab60e9e
diff --git a/Libraries/LibWeb/Rust/src/css/style/batch_matcher.rs b/Libraries/LibWeb/Rust/src/css/style/batch_matcher.rs
index 32db673c4a8..cf9792be06d 100644
--- a/Libraries/LibWeb/Rust/src/css/style/batch_matcher.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/batch_matcher.rs
@@ -80,7 +80,7 @@ pub struct RuleMatch {
/// Concrete matches for one evaluation, sorted by style node.
///
-/// This is transaction-local Tier-4 scratch: the cascade consumes it and it is discarded. It is not
+/// This is transaction-local scratch: the cascade consumes it and it is discarded. It is not
/// an inverse match relation and is never retained.
#[derive(Default)]
pub struct RuleMatches {
diff --git a/Libraries/LibWeb/Rust/src/css/style/cascade.rs b/Libraries/LibWeb/Rust/src/css/style/cascade.rs
index 30a9b61905d..f165bc78ba4 100644
--- a/Libraries/LibWeb/Rust/src/css/style/cascade.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/cascade.rs
@@ -618,7 +618,7 @@ pub(super) enum WinnerGroupCoverageGap {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum WinnerGroupTokenGap {
StaleGeneration { retained: u64, current: u64 },
- AdmissionClosed,
+ NotAnElement,
}
const WINNER_RULE_PAGE_SHIFT: usize = 6;
@@ -783,7 +783,6 @@ pub(super) struct WinnerEffects {
entries: Vec<PendingWinnerNode>,
writes: Vec<WinnerNodeWrite>,
by_node: Column<u32>,
- nested_bytes: usize,
}
#[derive(Clone, Copy)]
@@ -839,9 +838,7 @@ impl WinnerEffects {
}
fn push_write(&mut self, write: WinnerNodeWrite) {
- let capacity = self.writes.capacity();
self.writes.push(write);
- if capacity != self.writes.capacity() {}
}
pub(super) fn view<'a>(&'a self, groups: &'a WinnerGroups) -> WinnerView<'a> {
@@ -858,9 +855,6 @@ impl WinnerEffects {
state: CascadeStateID,
version: ProgramVersion,
) -> bool {
- if node.element_index().is_none() {
- return false;
- }
let Some(index) = self.entry_index(node) else {
return false;
};
@@ -901,9 +895,7 @@ impl WinnerEffects {
if let Some(row) = rows.iter_mut().find(|row| row.pseudo == pseudo) {
*row = new;
} else {
- let before = rows.capacity();
rows.push(new);
- self.nested_bytes += (rows.capacity() - before) * size_of::<PseudoWinnerRow>();
}
self.push_write(WinnerNodeWrite::Set {
node,
@@ -1006,7 +998,7 @@ impl WinnerEffects {
}
self.set(groups, node, state, version)
.then_some(())
- .ok_or(WinnerGroupTokenGap::AdmissionClosed)
+ .ok_or(WinnerGroupTokenGap::NotAnElement)
}
pub(super) fn copy_node_rows(
@@ -1294,9 +1286,8 @@ pub(super) struct StateSummary {
/// Interned per-node winning declarations.
///
/// Sparse and shared: never one heap object per property per element. A node retains one state
-/// identity, and states share property-range winner groups. The whole structure is Tier-3, so
-/// evicting it changes no semantic version and a later observer reconstructs a state from the
-/// node's cascade input or from the exact cold cascade.
+/// identity, and states share property-range winner groups. A node without a row reconstructs its
+/// state from its cascade input or from the exact cold cascade.
#[derive(Clone, Default)]
pub struct WinnerGroups {
states: InternTable<CascadeStateID, Box<[WinnerGroupRef]>>,
diff --git a/Libraries/LibWeb/Rust/src/css/style/catalog.rs b/Libraries/LibWeb/Rust/src/css/style/catalog.rs
index 0af8d3dea49..64ba28d15ca 100644
--- a/Libraries/LibWeb/Rust/src/css/style/catalog.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/catalog.rs
@@ -428,7 +428,7 @@ impl MatchAnswerCatalog {
.map(|entry| &entry.answer)
}
- pub(super) fn evict_retained(&mut self) {
+ pub(super) fn release_all_retained(&mut self) {
for index in 0..self.answers.len() {
let Some(entry) = self.answers[index].as_mut() else {
continue;
@@ -739,16 +739,8 @@ impl PrefixAnswerCache {
self.retained = false;
}
- pub(super) fn retain(&mut self) -> bool {
- if self.retained {
- return true;
- }
- if !true {
- return false;
- }
-
+ pub(super) fn retain(&mut self) {
self.retained = true;
- true
}
pub(super) fn make_scratch(&mut self) {
@@ -771,8 +763,8 @@ impl PrefixAnswerCache {
.is_some_and(|by_match_set| !by_match_set.is_empty())
{
// Canonical contributions are shared across programs. Dropping only this program's
- // lookup entries would leave unreachable contributions behind, so release the small,
- // evictable cache as one coherent unit.
+ // lookup entries would leave unreachable contributions behind, so release the small
+ // cache as one coherent unit.
self.release(catalog);
}
}
@@ -793,9 +785,8 @@ impl PrefixAnswerCache {
/// Exact selector answers retained as the old side of a later plan.
///
/// Cascade compaction is declaration-dependent, so the answer catalog keeps this stable selector
-/// payload and restores the current cascade rank when reading it. The per-node retained coverage is
-/// Tier-3: losing it turns the next declaration edit into an ordinary cold match without changing
-/// semantics.
+/// payload and restores the current cascade rank when reading it. A node without retained coverage
+/// turns the next declaration edit into an ordinary cold match without changing semantics.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub(super) struct RetainedRuleMatch {
pub(super) rule: RuleID,
@@ -893,7 +884,6 @@ pub(super) fn merge_retained_match_answers(answer: &mut Vec<RetainedRuleMatch>,
#[derive(Clone, Default)]
pub(super) struct PendingAnswer {
published_index: Option<usize>,
- observed: bool,
pub(super) identity: Option<Option<MatchAnswerID>>,
pub(super) cascade_input: Option<Option<MatchAnswerID>>,
}
@@ -910,7 +900,6 @@ pub(super) struct AnswerEffects {
by_node: PooledStampedIndex,
exact_answers: Vec<(OwnedPrefixAnswerKey, MatchAnswerID)>,
by_content: HashMap<u64, SmallVec<[usize; 1]>>,
- nested_bytes: usize,
}
impl AnswerEffects {
@@ -928,18 +917,6 @@ impl AnswerEffects {
self.entry(node).published_index = Some(index);
}
- pub(super) fn mark_observed(&mut self, node: StyleNodeID) {
- self.entry(node).observed = true;
- }
-
- pub(super) fn install_observations(&self, published: &mut PublishedMatchAnswers) {
- for &(node, ref entry) in &self.entries {
- if entry.observed {
- published.mark_observed(node);
- }
- }
- }
-
pub(super) fn lookup(&self, node: StyleNodeID) -> Option<&PendingAnswer> {
let index = self.by_node.get(node.element_index()? as usize)?;
Some(&self.entries[index as usize].1)
@@ -1033,18 +1010,7 @@ impl AnswerEffects {
) {
catalog.retain_pending(identity);
let bucket = self.by_content.entry(key.hash()).or_default();
- let old_bytes = if bucket.spilled() {
- bucket.capacity() * size_of::<usize>()
- } else {
- 0
- };
bucket.push(self.exact_answers.len());
- let new_bytes = if bucket.spilled() {
- bucket.capacity() * size_of::<usize>()
- } else {
- 0
- };
- self.nested_bytes += new_bytes - old_bytes + size_of_val(key.non_prefix_matches);
self.exact_answers.push((key.into_owned(), identity));
}
@@ -1115,8 +1081,6 @@ impl AnswerEffects {
for (key, identity) in self.exact_answers {
cache.install_exact_answer(catalog, key, identity);
}
-
- if !cache.retained {}
}
}
@@ -1130,8 +1094,8 @@ pub(super) struct RetainedMatchAnswers {
///
/// Active match answers normally discard a rule when its condition becomes false. This inverse
/// relation preserves the selector side of that join, so a later condition flip can route through
-/// exact selector truth without evaluating the selector again. It is Tier-3 state: incomplete
-/// retained coverage or closed admission simply leaves program routing on its cold path.
+/// exact selector truth without evaluating the selector again. Incomplete retained coverage simply
+/// leaves program routing on its cold path.
#[derive(Clone, Default)]
pub(super) struct RetainedSelectorIncidences {
by_program: Vec<Option<Arc<[RetainedSelectorIncidence]>>>,
@@ -1152,18 +1116,14 @@ impl RetainedSelectorIncidences {
&mut self,
program: SelectorProgramID,
incidences: Vec<RetainedSelectorIncidence>,
- ) -> Option<Arc<[RetainedSelectorIncidence]>> {
- if self.by_program.get(program.0 as usize).is_none_or(Option::is_none) && !true {
- return None;
- }
+ ) -> Arc<[RetainedSelectorIncidence]> {
let required_len = program.0 as usize + 1;
let incidences: Arc<[RetainedSelectorIncidence]> = incidences.into();
if self.by_program.len() < required_len {
self.by_program.resize(required_len, None);
}
self.by_program[program.0 as usize] = Some(Arc::clone(&incidences));
-
- Some(incidences)
+ incidences
}
pub(super) fn clear(&mut self) {
@@ -1306,7 +1266,7 @@ impl RetainedMatchAnswers {
answer: Vec<RetainedRuleMatch>,
programs: &SelectorPrograms,
) -> Result<(), Vec<RetainedRuleMatch>> {
- if node.element_index().is_none() || (self.answer_identity(node).is_none() && !true) {
+ if node.element_index().is_none() {
return Err(answer);
}
let identity = catalog.intern_prepared(answer, programs);
@@ -1406,8 +1366,8 @@ impl RetainedMatchAnswers {
self.forget_cascade_input(catalog, node);
}
- pub(super) fn evict(&mut self, catalog: &mut MatchAnswerCatalog) {
- catalog.evict_retained();
+ pub(super) fn clear(&mut self, catalog: &mut MatchAnswerCatalog) {
+ catalog.release_all_retained();
self.column = Vec::new();
}
}
@@ -1484,7 +1444,6 @@ pub(super) struct PublishedMatchAnswer {
pub(super) cascade_input: Option<MatchAnswerID>,
pub(super) matches: Option<Box<[RuleMatch]>>,
pub(super) cascade_winners_are_complete: bool,
- pub(super) observed: bool,
}
#[derive(Clone, Default)]
@@ -1553,13 +1512,6 @@ impl PublishedMatchAnswers {
self.entries.get(index)
}
- pub(super) fn mark_observed(&mut self, node: StyleNodeID) {
- let Ok(index) = self.entries.binary_search_by_key(&node, |entry| entry.node) else {
- return;
- };
- self.entries[index].observed = true;
- }
-
pub(super) fn matches_for<'a>(&'a self, answer: &'a PublishedMatchAnswer) -> Option<&'a [RuleMatch]> {
match answer.cascade_input {
Some(cascade_input) => self.shared_payloads.get(&cascade_input).map(Box::as_ref),
diff --git a/Libraries/LibWeb/Rust/src/css/style/column.rs b/Libraries/LibWeb/Rust/src/css/style/column.rs
index ddf3f71cc2c..a5136a3e1d3 100644
--- a/Libraries/LibWeb/Rust/src/css/style/column.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/column.rs
@@ -140,6 +140,10 @@ impl StampedIndex {
value,
};
}
+
+ fn capacity_bytes(&self) -> usize {
+ self.rows.capacity() * size_of::<StampedRow>()
+ }
}
thread_local! {
@@ -150,10 +154,11 @@ thread_local! {
/// the contexts a single matching pass has open, not the nodes it visits.
///
/// NB: A buffer in the pool is memory the process holds while no owner leases it. These bounds
-/// are what keep that off-book residency small: at most this many buffers, and at most this
-/// many bytes across all of them, since a buffer grows to the highest element identity it
-/// was ever asked for.
+/// are what keep that residency small: at most this many buffers, and at most this many bytes
+/// across all of them, since a buffer grows to the highest element identity it was ever asked
+/// for.
const STAMPED_INDEX_POOL_LIMIT: usize = 8;
+const STAMPED_INDEX_POOL_BYTE_LIMIT: usize = 4 << 20;
/// A [`StampedIndex`] taken from the thread's pool on first write and returned when dropped.
///
@@ -189,7 +194,10 @@ impl Drop for PooledStampedIndex {
};
let _ = STAMPED_INDEX_POOL.try_with(|pool| {
let mut pool = pool.borrow_mut();
- if pool.len() < STAMPED_INDEX_POOL_LIMIT {
+ let pooled_bytes: usize = pool.iter().map(StampedIndex::capacity_bytes).sum();
+ if pool.len() < STAMPED_INDEX_POOL_LIMIT
+ && pooled_bytes + borrowed.capacity_bytes() <= STAMPED_INDEX_POOL_BYTE_LIMIT
+ {
pool.push(borrowed);
}
});
diff --git a/Libraries/LibWeb/Rust/src/css/style/flush.rs b/Libraries/LibWeb/Rust/src/css/style/flush.rs
index 745516144d9..18faab499ff 100644
--- a/Libraries/LibWeb/Rust/src/css/style/flush.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/flush.rs
@@ -330,9 +330,9 @@ impl RetainedState {
.any(|kind| reads(self.computed_group_sets.pseudo_style_record(node, kind)))
}
- pub(super) fn prepare_topology_for_matching(&mut self, root: StyleNodeID, regions: &mut ImpactRegions) -> bool {
+ pub(super) fn prepare_topology_for_matching(&mut self, root: StyleNodeID, regions: &mut ImpactRegions) {
let Some(topology) = regions.take_topology() else {
- return false;
+ return;
};
match &mut self.prepared_batch_matching_traversal {
Some(prepared) => {
@@ -345,7 +345,6 @@ impl RetainedState {
self.prepared_batch_matching_traversal = Some(prepared);
}
}
- true
}
/// The feature the input is about, when the changed node is the one that carries it.
@@ -629,7 +628,7 @@ impl StyleEngine {
self.discard_retained_prefix_caches();
self.retained
.retained_match_answers
- .evict(&mut self.retained.match_answers);
+ .clear(&mut self.retained.match_answers);
self.release_transaction_and_sweep_atoms(transaction);
routing_setup_timer.stop(Counter::RoutingSetupMicroseconds, &self.retained.counters);
clock.enter(Counter::TransactionRemainderMicroseconds, &self.retained.counters);
@@ -639,7 +638,7 @@ impl StyleEngine {
// A preorder pass takes a step per element of the document, where a tree-shaped question
// walks the mandatory relation columns along a node's ancestors, and a transaction asks a
// few of them per input. A transaction this wide against its document amortizes the pass.
- // Keep the coordinates in Tier-4 scratch and let narrower updates walk the columns.
+ // Keep the coordinates in transaction scratch and let narrower updates walk the columns.
let mut regions =
if transaction.inputs.len().saturating_mul(16) >= self.retained.tree.connected_element_count() as usize {
ImpactRegions::with_topology(&self.retained.tree, root)
@@ -1661,7 +1660,6 @@ impl StyleEngine {
cascade_input: Some(answer.cascade_input),
matches: answer.matches.take(),
cascade_winners_are_complete: answer.cascade_winners_are_complete,
- observed: false,
}
})
.or_else(|| {
@@ -2064,7 +2062,7 @@ impl StyleEngine {
self.retained.prepared_batch_matching_traversal = Some(prepared);
}
}
- if !self.prepare_topology_for_matching(root, &mut regions) {}
+ self.prepare_topology_for_matching(root, &mut regions);
}
!publish_document_root_arrival && !plan_is_broad
}
@@ -2585,8 +2583,6 @@ impl StyleEngine {
}
}
}
- // NB: Sample scratch coexistence without scanning its containers per element.
- if (published_index + 1).is_multiple_of(256) {}
}
if suspended_on_font {
let request = pass.scratch.font_drive.take_suspended_request();
diff --git a/Libraries/LibWeb/Rust/src/css/style/index.rs b/Libraries/LibWeb/Rust/src/css/style/index.rs
index 3b5f1aac34f..bc7af702df3 100644
--- a/Libraries/LibWeb/Rust/src/css/style/index.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/index.rs
@@ -731,20 +731,6 @@ impl StyleNodeFacts {
}
}
- fn live_nodes(&self) -> impl Iterator<Item = StyleNodeID> + '_ {
- (0..self.row_count()).filter_map(|row| {
- let node = if self.primary {
- if row == 0 || !self.resident.contains(row) {
- return None;
- }
- StyleNodeID::element(u32::try_from(row).expect("element fact row exceeds u32"))
- } else {
- self.nodes[row]
- };
- (self.row_of(node) == u32::try_from(row).ok()).then_some(node)
- })
- }
-
#[must_use]
pub fn live_row_count(&self) -> usize {
self.live_rows
@@ -1487,17 +1473,15 @@ pub type PostingKey = FeatureKey;
/// Candidate sets for observed element features.
///
-/// This is acceleration and nothing more. Evicting a posting never changes which transpose entry
+/// This is acceleration and nothing more. A missing posting never changes which transpose entry
/// points run and never changes an answer: the routed program reads authoritative DOM facts or runs
/// an exact scope batch instead. Fact setters populate postings eagerly, independent of which
-/// selector programs are attached, and they remain until their facts disappear or eviction removes
-/// them. This global arrangement avoids program-lifetime registration and first-use fact scans;
-/// per-key missing coverage confines eviction fallout to the acceleration that was actually
-/// removed.
+/// selector programs are attached, and they remain until their facts disappear. A selector
+/// posting that outgrows its cardinality limit is dropped and stays missing for its key. This
+/// global arrangement avoids program-lifetime registration and first-use fact scans.
#[derive(Clone)]
pub struct FeaturePostings {
postings: HashMap<PostingKey, Posting>,
- missing: HashSet<PostingKey>,
cardinality_limited: HashSet<PostingKey>,
grown_selector_postings: HashSet<PostingKey>,
selector_posting_limit: usize,
@@ -1508,7 +1492,6 @@ impl Default for FeaturePostings {
Self {
postings: HashMap::default(),
- missing: HashSet::default(),
cardinality_limited: HashSet::default(),
grown_selector_postings: HashSet::default(),
selector_posting_limit: usize::MAX,
@@ -1518,15 +1501,14 @@ impl Default for FeaturePostings {
impl FeaturePostings {
#[must_use]
+ #[cfg(test)]
pub fn new() -> Self {
Self::default()
}
- /// Add `node` to a feature's candidate set. Once quota pressure closes admission, existing
- /// postings continue to accept members so they remain exact, while new posting keys stay
- /// missing until the next quota period.
+ /// Add `node` to a feature's candidate set. A key whose posting outgrew its limit stays missing.
pub fn insert(&mut self, key: PostingKey, node: StyleNodeID) -> bool {
- if self.missing.contains(&key) || self.cardinality_limited.contains(&key) {
+ if self.cardinality_limited.contains(&key) {
return false;
}
let posting = self.postings.entry(key).or_default();
@@ -1557,19 +1539,19 @@ impl FeaturePostings {
/// Look up one feature's complete candidate set.
///
- /// An absent key is known empty unless that exact posting was evicted or refused.
+ /// An absent key is known empty unless that exact posting outgrew its limit.
#[must_use]
pub(super) fn lookup(&self, key: PostingKey) -> Lookup<&Posting, PostingKey> {
match self.postings.get(&key) {
Some(posting) => Lookup::Known(posting),
- None if self.missing.contains(&key) || self.cardinality_limited.contains(&key) => Lookup::Missing(key),
+ None if self.cardinality_limited.contains(&key) => Lookup::Missing(key),
None => Lookup::KnownAbsent,
}
}
#[cfg(test)]
- pub(crate) fn evict(&mut self, key: PostingKey) {
- self.missing.insert(key);
+ pub(crate) fn drop_posting(&mut self, key: PostingKey) {
+ self.cardinality_limited.insert(key);
self.remove_posting(key);
}
@@ -1625,27 +1607,6 @@ impl FeaturePostings {
self.grown_selector_postings = grown;
}
- #[must_use]
- fn is_incomplete(&self) -> bool {
- !self.missing.is_empty()
- }
-
- fn take_rebuilt(&mut self, mut rebuilt: FeaturePostings) {
- debug_assert!(rebuilt.missing.is_empty());
-
- rebuilt.grown_selector_postings = HashSet::default();
-
- self.postings.extend(rebuilt.postings.drain());
-
- rebuilt.postings = HashMap::default();
-
- self.cardinality_limited.extend(rebuilt.cardinality_limited.drain());
-
- rebuilt.cardinality_limited = HashSet::default();
-
- self.missing = HashSet::default();
- }
-
#[must_use]
#[cfg(test)]
pub fn feature_count(&self) -> usize {
@@ -1659,8 +1620,6 @@ impl FeaturePostings {
self.postings = HashMap::default();
}
- self.missing
- .retain(|key| !key.atom().is_some_and(|atom| atoms.contains(&atom)));
self.cardinality_limited
.retain(|key| !key.atom().is_some_and(|atom| atoms.contains(&atom)));
self.grown_selector_postings
@@ -2047,8 +2006,8 @@ fn dispatch_atom_bucket_key(kind: usize, atom: usize) -> DispatchKey {
///
/// A candidate probes only the buckets its own facts name, plus the universal bucket, so a document
/// full of `.item` elements never considers a rule whose subject compound requires `#header`. This
-/// is program-derived dispatch rather than acceleration over elements: it is Tier 2, it is rebuilt
-/// with the program, and it is never evicted independently of it.
+/// is program-derived dispatch rather than acceleration over elements: it is rebuilt with the
+/// program and never dropped independently of it.
#[derive(Default)]
pub(super) struct AncestorDispatchTopology {
key_indices: HashMap<DispatchKey, u32>,
@@ -2489,7 +2448,7 @@ impl RuleDispatch {
/// Assign a dense rank to the static cascade priority of every selector entry.
///
- /// The dispatch is Tier 2 program data, so a rule or ordering change rebuilds these ranks along
+ /// The dispatch is program data, so a rule or ordering change rebuilds these ranks along
/// with the buckets. Dynamic `@scope` proximity is deliberately absent and makes the consumer
/// fall back to constructing the complete priority.
///
@@ -3154,9 +3113,8 @@ pub struct ElementFactStore {
/// Candidate sets over the same facts. A rule arriving needs to find the elements it could
/// match without walking the document, and this is what answers that.
postings: crate::fork::ForkShared<FeaturePostings>,
- /// Tier-3 headroom when admission last closed during a full rebuild. Until more headroom
- /// appears, another scan can only reach the same closure.
- memory_dirty: bool,
+ /// Whether fact staging holds edits `apply_staged` has not committed yet.
+ staging_dirty: bool,
/// One entry per distinct set of declared custom property names, and the sets each name is in.
/// A theme is one set however many elements it decides for, which is what keeps the index
/// proportional to the stylesheet rather than to the document times the stylesheet.
@@ -3434,7 +3392,7 @@ impl Default for ElementFactStore {
metadata: Column::default(),
postings: Default::default(),
- memory_dirty: false,
+ staging_dirty: false,
custom_property_name_sets: super::intern_table::InternTable::default(),
custom_property_name_set_vacancies: Vec::new(),
custom_property_set_ids_by_name: PagedOwnedColumn::default(),
@@ -3646,112 +3604,6 @@ impl ElementFactStore {
&self.postings
}
- fn rebuild_missing_posting(&self, rebuilt: &mut FeaturePostings, key: PostingKey, node: StyleNodeID) -> bool {
- !self.postings.missing.contains(&key) || rebuilt.insert(key, node) || rebuilt.cardinality_limited.contains(&key)
- }
-
- fn build_missing_postings(&self) -> Option<FeaturePostings> {
- let mut rebuilt = FeaturePostings::new();
- rebuilt.selector_posting_limit = self.postings.selector_posting_limit;
- for node in self.rows.live_nodes() {
- let row = self.rows.row_of(node).expect("a live node must have a fact row");
- for (atom, key) in [
- (
- self.rows.tag_of(row),
- SelectorPostingKey::TagName(self.rows.tag_of(row)),
- ),
- (
- self.rows.folded_tag_of(row),
- SelectorPostingKey::TagName(self.rows.folded_tag_of(row)),
- ),
- (self.rows.id_of(row), SelectorPostingKey::Id(self.rows.id_of(row))),
- (
- self.rows.directionality_of(row),
- SelectorPostingKey::Directionality(self.rows.directionality_of(row)),
- ),
- ] {
- if atom.is_none() {
- continue;
- }
- if !self.rebuild_missing_posting(&mut rebuilt, key, node) {
- return None;
- }
- }
- for &part in self.rows.parts_of(row) {
- let key = SelectorPostingKey::Part(part);
- if !self.rebuild_missing_posting(&mut rebuilt, key, node) {
- return None;
- }
- }
- for &state in self.rows.custom_states_of(row) {
- let key = SelectorPostingKey::CustomState(state);
- if !self.rebuild_missing_posting(&mut rebuilt, key, node) {
- return None;
- }
- }
- for state in self
- .rows
- .states_of(row)
- .facts()
- .filter(|state| state.has_selector_posting())
- {
- let key = SelectorPostingKey::State(state);
- if !self.rebuild_missing_posting(&mut rebuilt, key, node) {
- return None;
- }
- }
- for &class in self.rows.classes_of(row) {
- let key = SelectorPostingKey::Class(class);
- if !self.rebuild_missing_posting(&mut rebuilt, key, node) {
- return None;
- }
- }
- for attribute in self.rows.attributes_of(row) {
- for name in self.attribute_name_keys(attribute.name) {
- let key = SelectorPostingKey::AttributeName(name);
- if !self.rebuild_missing_posting(&mut rebuilt, key, node) {
- return None;
- }
- }
- }
- if let Some(metadata) = self.metadata_of(node) {
- for &name in &metadata.animation_names {
- let key = DependencyPostingKey::AnimationName(name);
- if !self.rebuild_missing_posting(&mut rebuilt, key, node) {
- return None;
- }
- }
- if metadata.custom_property_set != 0 {
- let key = DependencyPostingKey::CustomPropertySet(metadata.custom_property_set);
- if !self.rebuild_missing_posting(&mut rebuilt, key, node) {
- return None;
- }
- }
- for (uses, key) in [
- (
- metadata.uses_unnamed_custom_properties,
- DependencyPostingKey::AnyCustomProperty,
- ),
- (metadata.uses_custom_functions, DependencyPostingKey::AnyCustomFunction),
- ] {
- if uses && !self.rebuild_missing_posting(&mut rebuilt, key, node) {
- return None;
- }
- }
- }
- }
- Some(rebuilt)
- }
-
- fn rebuild_missing_postings(&mut self) {
- if !self.postings.is_incomplete() {
- return;
- }
- if let Some(rebuilt) = self.build_missing_postings() {
- self.postings.take_rebuilt(rebuilt);
- }
- }
-
#[must_use]
pub fn primary(&self) -> &StyleNodeFacts {
assert!(
@@ -3805,7 +3657,7 @@ impl ElementFactStore {
}
fn metadata_mut(&mut self, node: StyleNodeID) -> &mut ElementFactMetadata {
- self.memory_dirty = true;
+ self.staging_dirty = true;
let index = node.element_index().expect("only elements carry element facts") as usize;
self.metadata
.entry(index)
@@ -3842,7 +3694,7 @@ impl ElementFactStore {
}
fn edit_staged_row<R>(&mut self, node: StyleNodeID, edit: impl FnOnce(&mut StagedFactRow) -> R) -> R {
- self.memory_dirty = true;
+ self.staging_dirty = true;
if !self.staging.contains(node) {
let before = self.rows.row_of(node).map(|row| self.rows.primary_snapshot(row));
let row = before.map_or_else(StagedFactRow::default, |snapshot| {
@@ -3861,7 +3713,7 @@ impl ElementFactStore {
/// that lands there - asks for a row that never arrives and the whole match gives up.
pub fn ensure_row(&mut self, node: StyleNodeID) {
if self.rows.row_of(node).is_none() && !self.staging.contains(node) {
- self.memory_dirty = true;
+ self.staging_dirty = true;
self.staging.insert(node, StagedFactRow::default(), None);
}
}
@@ -4055,7 +3907,7 @@ impl ElementFactStore {
/// An element's heading level follows from what it is, so it is published as it arrives and
/// whenever an `aria-level` that overrides it moves.
pub fn set_is_slot(&mut self, node: StyleNodeID, is_slot: bool) {
- self.memory_dirty = true;
+ self.staging_dirty = true;
if is_slot {
self.metadata_mut(node).is_slot = true;
} else if let Some(metadata) = node
@@ -4093,7 +3945,7 @@ impl ElementFactStore {
{
return;
}
- self.memory_dirty = true;
+ self.staging_dirty = true;
self.attribute_catalogs_mut()
.language_texts
.insert(index, Some(text.into()));
@@ -4236,7 +4088,7 @@ impl ElementFactStore {
/// per element is millions of entries for one answer. The set is stored once, the element
/// names it by identity, and a registration asks which sets hold its name.
pub fn set_custom_property_names(&mut self, node: StyleNodeID, names: &[StyleAtomID]) {
- self.memory_dirty = true;
+ self.staging_dirty = true;
// The caller hands these sorted and deduplicated, worked out once for the environment the
// element resolved to.
debug_assert!(names.windows(2).all(|pair| pair[0].0 < pair[1].0));
@@ -4369,7 +4221,7 @@ impl ElementFactStore {
kind: ElementDeclarationKind,
declarations: Vec<(DeclaredProperty, RetainedStyleValueData)>,
) {
- self.memory_dirty = true;
+ self.staging_dirty = true;
self.element_declared_properties.set(node, kind, declarations);
}
@@ -4380,7 +4232,7 @@ impl ElementFactStore {
node: StyleNodeID,
custom_declarations: Vec<(CustomDeclaration, RetainedStyleValueData)>,
) {
- self.memory_dirty = true;
+ self.staging_dirty = true;
self.element_declared_properties.set_custom(node, custom_declarations);
}
@@ -4403,7 +4255,7 @@ impl ElementFactStore {
rows.rows_with_custom_declarations -= 1;
}
rows.payload_bytes = rows.payload_bytes - before + row.storage_bytes();
- self.memory_dirty = true;
+ self.staging_dirty = true;
Some(hidden)
}
@@ -4425,7 +4277,7 @@ impl ElementFactStore {
rows.rows_with_custom_declarations += 1;
}
rows.payload_bytes = rows.payload_bytes - before + row.storage_bytes();
- self.memory_dirty = true;
+ self.staging_dirty = true;
}
/// The custom properties the node's inline style declares, in declaration order.
@@ -4471,13 +4323,13 @@ impl ElementFactStore {
/// idempotent and total: every attribute name goes through it, including one in no namespace,
/// whose local form is still an atom of its own.
pub fn note_attribute_name_forms(&mut self, name: StyleAtomID, forms: AttributeNameForms) {
- self.memory_dirty = true;
+ self.staging_dirty = true;
self.attribute_catalogs_mut().name_forms.insert(name.0 as usize, forms);
}
/// Record the local name an `attr()` reads the attribute `name` by, which is in no namespace.
pub fn note_attribute_substitution_name(&mut self, name: StyleAtomID, local_name: &[u16]) {
- self.memory_dirty = true;
+ self.staging_dirty = true;
self.attribute_catalogs_mut()
.substitution_names
.insert(name.0 as usize, Some(local_name.into()));
@@ -4523,7 +4375,7 @@ impl ElementFactStore {
{
return;
}
- self.memory_dirty = true;
+ self.staging_dirty = true;
self.attribute_catalogs_mut()
.value_texts
.insert(index, Some(text.into()));
@@ -4592,7 +4444,7 @@ impl ElementFactStore {
}
pub fn forget(&mut self, node: StyleNodeID) {
- self.memory_dirty = true;
+ self.staging_dirty = true;
self.element_declared_properties.remove(node);
self.staging.remove(node);
let Some(row) = self.rows.row_of(node) else {
@@ -4678,7 +4530,7 @@ impl ElementFactStore {
/// NB: A retained traversal or a fork of the store may share the primary rows. The sweep writes only the store's
/// own catalogs, and `prepare_attribute_catalogs` copies the rows where they are shared.
pub(super) fn sweep_auxiliary_catalogs_without_sync(&mut self) {
- self.memory_dirty = true;
+ self.staging_dirty = true;
let attribute_catalogs = Arc::make_mut(&mut self.attribute_catalogs);
// Language spellings and attribute-name forms are retained until their atom is reclaimed;
// forget_atoms clears them at that authoritative boundary so a reused identity can publish
@@ -4723,7 +4575,7 @@ impl ElementFactStore {
if atoms.is_empty() {
return;
}
- self.memory_dirty = true;
+ self.staging_dirty = true;
let atoms = atoms.iter().copied().collect::<HashSet<_>>();
let catalogs = Arc::make_mut(&mut self.attribute_catalogs);
for atom in &atoms {
@@ -4804,8 +4656,7 @@ impl ElementFactStore {
/// Commit every fact-staging edit to the authoritative arrangement.
pub fn apply_staged(&mut self) {
- if !self.memory_dirty {
- self.rebuild_missing_postings();
+ if !self.staging_dirty {
return;
}
self.prepare_attribute_catalogs();
@@ -4825,8 +4676,7 @@ impl ElementFactStore {
self.staging = staging;
self.postings.update_selector_posting_limit(self.rows.live_row_count());
- self.memory_dirty = false;
- self.rebuild_missing_postings();
+ self.staging_dirty = false;
}
/// Snapshot the committed rows which staged local facts will replace at the barrier.
@@ -5383,7 +5233,7 @@ mod tests {
let absent = SelectorPostingKey::Class(StyleAtomID(2));
postings.insert(evicted, StyleNodeID::element(1));
- postings.evict(evicted);
+ postings.drop_posting(evicted);
assert!(matches!(postings.lookup(evicted), Lookup::Missing(gap) if gap == evicted));
assert!(matches!(postings.lookup(absent), Lookup::KnownAbsent));
diff --git a/Libraries/LibWeb/Rust/src/css/style/inputs.rs b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
index 3e71b9eeb8f..78e5f29d7dd 100644
--- a/Libraries/LibWeb/Rust/src/css/style/inputs.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
@@ -2038,7 +2038,6 @@ impl StyleEngine {
retained_selector_incidences: RetainedSelectorIncidences::default(),
selector_incidence_is_current: false,
batch_matching_traversal: None,
- completion_exactness: CompletionExactness::Exact,
route_pruning_states: crate::fork::ForkReset::new(Mutex::new(RoutePruningStateCache::default())),
sibling_positions: crate::fork::ForkReset::default(),
prefix_caches: std::sync::Arc::default(),
@@ -2132,7 +2131,7 @@ impl StyleEngine {
for &(node, relations) in arrivals {
self.link(node, relations);
}
- self.publish_budget_inputs();
+ self.update_journal_entry_limit();
let root_relations = arrivals
.iter()
@@ -2750,7 +2749,7 @@ impl StyleEngine {
.add(Counter::StyleNodesRetired, retired_nodes.len() as u64);
}
self.host.tree_staging.mark_applied();
- self.publish_budget_inputs();
+ self.update_journal_entry_limit();
}
/// Name the node a style scope belongs to. A shadow root is a scope and a subtree at once, which
@@ -2907,7 +2906,7 @@ impl StyleEngine {
}
}
if minted_an_element {
- self.publish_budget_inputs();
+ self.update_journal_entry_limit();
}
}
@@ -3421,7 +3420,6 @@ impl RetainedState {
route_pruning_states: _,
// Keyed by the tree's DOM order version.
sibling_positions: _,
- completion_exactness: _,
// Dropped in `forget_departed_elements` when a relation holds a departed element.
prefix_caches: _,
#[cfg(test)]
diff --git a/Libraries/LibWeb/Rust/src/css/style/instrumentation.rs b/Libraries/LibWeb/Rust/src/css/style/instrumentation.rs
index da6736173a6..566627c655b 100644
--- a/Libraries/LibWeb/Rust/src/css/style/instrumentation.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/instrumentation.rs
@@ -187,8 +187,6 @@ define_counters! {
PrefixLocalFactIdentityMisses => "prefixLocalFactIdentityMisses",
PrefixAnswerCacheHits => "prefixAnswerCacheHits",
PrefixAnswerCacheMisses => "prefixAnswerCacheMisses",
- Tier3BenefitEvictions => "tier3BenefitEvictions",
- Tier3RefusalRetainedMatchAnswerBytes => "tier3RefusalRetainedMatchAnswerBytes",
MatchAnswerSignatures => "matchAnswerSignatures",
MatchAnswerSignatureReuses => "matchAnswerSignatureReuses",
SelectorTruthSetMisses => "selectorTruthSetMisses",
@@ -215,7 +213,6 @@ define_counters! {
PublishedMatchAnswerClosureCompletions => "publishedMatchAnswerClosureCompletions",
PublishedClosureRetainedIdentityStops => "publishedClosureRetainedIdentityStops",
MatchElementCallsDuringPublishedStyleTransaction => "matchElementCallsDuringPublishedStyleTransaction",
- RetainedMatchAnswerRefusals => "retainedMatchAnswerRefusals",
RetainedMatchAnswerPatches => "retainedMatchAnswerPatches",
RetainedMatchAnswerDeltaPatches => "retainedMatchAnswerDeltaPatches",
RetainedMatchAnswerDeltaMemoHits => "retainedMatchAnswerDeltaMemoHits",
diff --git a/Libraries/LibWeb/Rust/src/css/style/matching.rs b/Libraries/LibWeb/Rust/src/css/style/matching.rs
index bfd3f432234..27b9faea8aa 100644
--- a/Libraries/LibWeb/Rust/src/css/style/matching.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/matching.rs
@@ -218,13 +218,11 @@ impl RetainedState {
pub(super) fn discard_published_match_answers(&mut self) {
if let Some(traversal) = self.batch_matching_traversal.as_mut() {
let effects = std::mem::take(&mut traversal.answer_effects);
- effects.install_observations(&mut self.published_match_answers);
effects.release_pending_all(&mut self.match_answers, &mut self.winner_groups);
traversal.pending_published.clear();
}
let mut published = std::mem::take(&mut self.published_match_answers);
let effects = std::mem::take(&mut published.answer_effects);
- effects.install_observations(&mut published);
effects.release_pending_all(&mut self.match_answers, &mut self.winner_groups);
verify_published_style_transaction(self, |_| {
assert!(
@@ -288,9 +286,7 @@ impl RetainedState {
}
pub(super) fn retain_prefix_states(&mut self) {
- if !self.prefix_caches.borrow_mut().states.retain() {
- self.prefix_caches.borrow_mut().states.release_transition_states();
- }
+ self.prefix_caches.borrow_mut().states.retain();
}
pub(super) fn take_prepared_batch_matching_traversal(
@@ -323,13 +319,6 @@ impl RetainedState {
prefer_complete_batch: bool,
) {
debug_assert!(self.batch_matching_traversal.is_none());
- // Each completion batch may ask for exact answers again after a quota boundary reopened
- // retained-answer admission.
- self.completion_exactness = if true {
- CompletionExactness::Exact
- } else {
- CompletionExactness::AllowPruning
- };
let materialize_timer = flush::PassTimer::start();
let batch = prefer_complete_batch
.then(|| {
@@ -426,20 +415,13 @@ impl RetainedState {
// The batch extended states describing this transaction's facts, so retain their shared
// owner instead of discarding them: the next flush's walk completes over
// warm spines. The sparse origin flag keeps that walk from letting the cache speak for
- // nodes the batch never visited. Unlike the walk's bootstrap retention, this is an
- // opportunistic give-back. If admission already closed, both scratch caches are released.
+ // nodes the batch never visited.
{
let mut caches = self.prefix_caches.borrow_mut();
caches.states.mark_sparse();
- if caches.states.retain() {
- caches.states.mark_current();
- if !caches.answers.retain() {
- caches.answers.release(&mut self.match_answers);
- }
- } else {
- caches.states.release_transition_states();
- caches.answers.release(&mut self.match_answers);
- }
+ caches.states.retain();
+ caches.states.mark_current();
+ caches.answers.retain();
}
self.forget_custom_property_environments_by_answer();
@@ -497,8 +479,8 @@ impl RetainedState {
/// Materialize the document's facts once for a synchronous broad style traversal.
///
/// The caller brackets one traversal explicitly, so engine mutations cannot leave a retained
- /// answer stale. If the batch exceeds the document's Tier-4 budget, drop it and let each
- /// element use the ordinary exact batch path.
+ /// answer stale. If the batch cannot be materialized, let each element use the ordinary exact
+ /// batch path.
pub fn begin_cold_matching_batch(&mut self, root: StyleNodeID) -> bool {
self.end_cold_matching_batch();
@@ -657,13 +639,8 @@ impl RetainedState {
.install(&mut self.prefix_caches.borrow_mut().states);
self.retain_prefix_states();
let mut caches = self.prefix_caches.borrow_mut();
- let retained_prefix_states = caches.states.is_retained();
- if retained_prefix_states {
- caches.states.mark_full();
- }
- if !retained_prefix_states || !caches.answers.retain() {
- caches.answers.release(&mut self.match_answers);
- }
+ caches.states.mark_full();
+ caches.answers.retain();
drop(caches);
self.forget_custom_property_environments_by_answer();
self.match_answers.sweep_unreferenced();
@@ -1392,15 +1369,8 @@ impl RetainedState {
WitnessEffect::Clear(key) => self.relational_witnesses.clear(key),
}
}
-
- self.settle_relational_witness_memory();
}
- /// Keep the retained-witness charge in step with the table. Capacity is already committed
- /// at this boundary, so pressure keeps the table usable for this period and schedules the whole
- /// category for eviction at the next boundary.
- pub(super) fn settle_relational_witness_memory(&mut self) {}
-
/// Return the retained witness proving that this anchor's Boolean cannot have flipped.
///
/// The entry only proves that the anchor's last completed evaluation of the query answered
@@ -1679,14 +1649,7 @@ impl RetainedState {
node: StyleNodeID,
identity: MatchAnswerID,
) -> bool {
- let Some(index) = node.element_index().map(|index| index as usize) else {
- return false;
- };
- // NB: Column growth is deferred to installation. During an admitting batch,
- // a pending exact answer can be reused before that growth has happened.
- if (index >= self.retained_match_answers.column.capacity() && !true)
- || self.match_answers.answer(identity).is_none()
- {
+ if node.element_index().is_none() || self.match_answers.answer(identity).is_none() {
return false;
}
if effects.answer_identity(&self.retained_match_answers, node) == Some(identity) {
@@ -1702,7 +1665,6 @@ impl RetainedState {
pub(super) fn install_answer_effects(&mut self, mut effects: AnswerEffects) {
self.install_winner_effects(std::mem::take(&mut effects.winners));
- effects.install_observations(&mut self.published_match_answers);
effects.install(
&mut self.retained_match_answers,
&mut self.match_answers,
@@ -1830,18 +1792,12 @@ impl RetainedState {
Counter::SelectorTruthDerivedAnswerMisses
});
}
- if node.element_index().is_some()
- && (effects.answer_identity(&self.retained_match_answers, node).is_some() || true)
- {
- let identity = self.match_answers.intern_prepared(answer, &self.programs);
- if effects.answer_identity(&self.retained_match_answers, node) != Some(identity) {
- effects.remember_identity(node, identity, &mut self.match_answers);
- }
+ if node.element_index().is_none() {
return;
}
- if effects.answer_identity(&self.retained_match_answers, node).is_none() {
- self.counters.bump(Counter::RetainedMatchAnswerRefusals);
- if self.counters.get(Counter::Tier3RefusalRetainedMatchAnswerBytes) == 0 {}
+ let identity = self.match_answers.intern_prepared(answer, &self.programs);
+ if effects.answer_identity(&self.retained_match_answers, node) != Some(identity) {
+ effects.remember_identity(node, identity, &mut self.match_answers);
}
}
@@ -1878,7 +1834,7 @@ impl RetainedState {
}
incidences.sort_unstable();
incidences.dedup();
- self.retained_selector_incidences.remember(program, incidences)
+ Some(self.retained_selector_incidences.remember(program, incidences))
}
/// Materialize several active programs' selector incidences in one retained-answer pass.
@@ -2039,7 +1995,7 @@ impl RetainedState {
}
incidences.truncate(selected_count);
incidences.sort_unstable();
- self.retained_selector_incidences.remember(program, incidences)
+ Some(self.retained_selector_incidences.remember(program, incidences))
}
/// Read one selector entry's pre-transaction truth from the retained exact answer.
@@ -3429,16 +3385,13 @@ impl RetainedState {
self.counters.bump(Counter::RetainedMatchAnswerReuses);
(answer, cascade_winners_are_complete, None)
} else {
- // Exactness is selected before the batch. Allocation by an earlier node
- // cannot change the matching discipline of a later node in this loop.
- let completion_exactness = self.completion_exactness;
let mut compact_answer = None;
let mut cascade_winners_are_complete = false;
let answer = self.match_element_in_traversal(
effects,
node,
true,
- completion_exactness,
+ CompletionExactness::Exact,
traversal,
Some(&mut compact_answer),
Some(&mut cascade_winners_are_complete),
@@ -3452,7 +3405,6 @@ impl RetainedState {
cascade_input,
matches: compact_answer.is_none().then(|| matches.into_boxed_slice()),
cascade_winners_are_complete,
- observed: false,
})
}
@@ -3489,7 +3441,6 @@ impl RetainedState {
cascade_input: None,
matches: None,
cascade_winners_are_complete: false,
- observed: false,
});
};
self.match_answers.answer(cascade_input)?;
@@ -3507,7 +3458,6 @@ impl RetainedState {
cascade_input: Some(cascade_input),
matches: None,
cascade_winners_are_complete,
- observed: false,
})
}
@@ -3537,7 +3487,6 @@ impl RetainedState {
cascade_input: Some(cascade_input),
matches: None,
cascade_winners_are_complete,
- observed: false,
})
}
@@ -3823,7 +3772,6 @@ impl RetainedState {
cascade_input: Some(cascade_input),
matches: None,
cascade_winners_are_complete: false,
- observed: false,
}
} else {
self.complete_published_match_answer_in_traversal(
@@ -3907,7 +3855,7 @@ impl RetainedState {
}
/// Publish new winners from the retained selector answer, matching from published facts when
- /// that answer has been evicted. `None` when neither can say what the node matches; else
+ /// there is none. `None` when neither can say what the node matches; else
/// whether the winners are complete.
pub(super) fn republish_winners_from_answer(
&mut self,
@@ -3937,7 +3885,6 @@ impl RetainedState {
cascade_input: None,
matches: Some(matches.into_boxed_slice()),
cascade_winners_are_complete: complete,
- observed: false,
},
&self.counters,
);
@@ -4080,14 +4027,6 @@ impl RetainedState {
published.lookup(node).map(|answer| (published, answer))
}
- pub(super) fn mark_published_answer_observed(&mut self, node: StyleNodeID) {
- if let Some(traversal) = self.batch_matching_traversal.as_mut() {
- traversal.answer_effects.mark_observed(node);
- } else {
- self.published_match_answers.answer_effects.mark_observed(node);
- }
- }
-
pub(super) fn consume_published_match_answer_in_traversal(
&mut self,
effects: &mut AnswerEffects,
@@ -4125,7 +4064,6 @@ impl RetainedState {
}
}
if let Some(mut matches) = matches {
- effects.mark_observed(node);
for entry in &mut matches {
entry.node = node;
}
@@ -4167,9 +4105,9 @@ impl RetainedState {
}
let generation = winner_groups.generation();
// A held pseudo style the engine has no record of cannot be vouched for: winner rows and
- // computed cascade records are the only witnesses the two arms below can judge, and a
- // Tier-3 eviction can strip both while the consumer still holds the computed style. With
- // no witness the answer must be a recompute, never a vacuous pass.
+ // computed cascade records are the only witnesses the two arms below can judge, and the
+ // consumer can hold a computed style with neither. With no witness the answer must be a
+ // recompute, never a vacuous pass.
let held_kinds_are_witnessed = self.computed_group_sets.assigned_pseudo_kinds(node).all(|kind| {
self.computed_group_sets
.pseudo_retained_cascade_state(node, kind)
diff --git a/Libraries/LibWeb/Rust/src/css/style/mod.rs b/Libraries/LibWeb/Rust/src/css/style/mod.rs
index 919cff4acba..a898d179848 100644
--- a/Libraries/LibWeb/Rust/src/css/style/mod.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/mod.rs
@@ -12,11 +12,9 @@
//! logical dependency program. A style flush discovers and propagates exact changes through that
//! program and stops as soon as a semantic value is unchanged.
//!
-//! Two properties shape every module here. First, memory is a primary constraint: derived state is
-//! tiered (see [`memory`]), budgeted, and - above Tier 2 - discardable at any time without affecting
-//! correctness. Second, the cache-free exact matcher is part of the architecture rather than a
-//! fallback bolted on: optional incremental state may accelerate matching but is never required to
-//! answer a style read correctly.
+//! The cache-free exact matcher is part of the architecture rather than a fallback bolted on:
+//! optional incremental state may accelerate matching but is never required to answer a style read
+//! correctly. Derived state lives as long as the node or rule it describes.
//!
//! Everything between a style input and a computed value is authoritative here, on the Rust side.
//! C++ remains authoritative for DOM and CSSOM object identity, mutation semantics, document
@@ -981,8 +979,8 @@ pub struct RetainedState {
retained_selector_incidences: RetainedSelectorIncidences,
/// Whether the current transaction changes activation without changing selector inputs.
selector_incidence_is_current: bool,
- /// Read-through facts shared by one synchronous style traversal. This is Tier-4 scratch, not
- /// retained matching state. A broad traversal begins with a complete batch; a selective one
+ /// Read-through facts shared by one synchronous style traversal. This is transaction scratch,
+ /// not retained matching state. A broad traversal begins with a complete batch; a selective one
/// promotes only after repeated local packing clears its rebuild-cost hysteresis.
/// The transaction or host-call adapter owns the box while matching borrows its scratch.
/// Moving the box at those boundaries leaves the fact batch's vector headers in place.
@@ -996,22 +994,18 @@ pub struct RetainedState {
/// The places of the children of parents with many of them, which sibling-counting functions
/// read, kept while the tree's DOM order stands.
sibling_positions: crate::fork::ForkReset<Mutex<publication::SiblingPositionCache>>,
- /// Once Tier-3 pressure closes retained-answer admission, the rest of the completion batch
- /// stops asking for exact answers: an exact answer costs more to evaluate, and paying that
- /// premium for an answer the controller cannot retain buys nothing on any later flush.
- completion_exactness: CompletionExactness,
/// Prefix transitions and their canonical answers have one document-lifetime owner. Matching
/// traversals and answer patches borrow it synchronously and change its cache-owned lifecycle
- /// between scratch and retained residency without moving the payload.
+ /// between scratch and retained without moving the payload.
prefix_caches: std::sync::Arc<SharedPrefixCaches>,
- /// Test-only: force the bounded completion window regardless of headroom.
+ /// Test-only: force the bounded completion window.
#[cfg(test)]
force_bounded_prefix_completion: bool,
/// Current-side scratch an exact transaction already produced for the style consumer
/// that immediately consumes it. Any intervening engine mutation discards it.
prepared_batch_matching_traversal: Option<PreparedBatchMatchingTraversal>,
/// Complete compact answers owned by the scoped style transaction which the next traversal
- /// consumes. This is required Tier-4 scratch, not a persistent inverse match relation.
+ /// consumes. This is transaction scratch, not a persistent inverse match relation.
published_match_answers: PublishedMatchAnswers,
transaction_fact_view: Option<TransactionFactView>,
facts: crate::fork::ForkShared<ElementFactStore>,
diff --git a/Libraries/LibWeb/Rust/src/css/style/ordering.rs b/Libraries/LibWeb/Rust/src/css/style/ordering.rs
index 9a36ab0e11f..1098f6853ba 100644
--- a/Libraries/LibWeb/Rust/src/css/style/ordering.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/ordering.rs
@@ -120,7 +120,6 @@ struct RememberedCompactions {
/// The hashes of the lists compacted once since the table was last cleared.
seen: HashSet<u64>,
by_matches: hashbrown::HashTable<RememberedCompaction>,
- nested_bytes: usize,
}
impl RememberedCompactions {
@@ -143,7 +142,6 @@ impl RememberedCompactions {
fn clear(&mut self) {
self.by_matches.clear();
- self.nested_bytes = 0;
}
fn get(&self, hash: u64, matches: &[CompactionKeyPart]) -> Option<&RememberedCompaction> {
@@ -176,13 +174,6 @@ impl RememberedCompactions {
states: states.into(),
keep: keep.map(Into::into),
};
- self.nested_bytes += size_of_val(remembered.matches.as_ref())
- + keep.map_or(0, size_of_val)
- + if remembered.states.spilled() {
- size_of_val(states)
- } else {
- 0
- };
self.by_matches
.insert_unique(hash, remembered, |remembered| remembered.hash);
}
@@ -984,9 +975,10 @@ impl RetainedState {
// from the answer again (`winner_below_substitution`), so a match declaring such a
// property is kept whatever else it loses.
if keep.iter().any(|kept| !kept) {
- let may_substitute_revert = |value| match self.specified_values.value(value) {
- Lookup::Known(value) => custom_property_cascade::value_may_substitute_revert(value),
- _ => false,
+ let may_substitute_revert = |value| {
+ self.specified_values
+ .value(value)
+ .is_some_and(custom_property_cascade::value_may_substitute_revert)
};
let mut substituted: SmallVec<[(Option<tree::PseudoElementTarget>, u16); 4]> = SmallVec::new();
let top_1_winners = top_1.unordered_winners().map(|winner| (winner.key, winner.payload));
@@ -1119,10 +1111,9 @@ impl RetainedState {
/// name.
fn state_may_substitute_revert(&self, state: CascadeStateID) -> bool {
self.winner_groups.winners_in_state(state).any(|winner| {
- matches!(
- self.specified_values.value(winner.key.value),
- Lookup::Known(value) if custom_property_cascade::value_may_substitute_revert(value)
- )
+ self.specified_values
+ .value(winner.key.value)
+ .is_some_and(custom_property_cascade::value_may_substitute_revert)
})
}
@@ -2272,9 +2263,9 @@ impl StyleEngine {
}
}
- /// The document budget is written in connected elements, so it has to follow the live element
- /// count rather than a high-water mark.
- pub(super) fn publish_budget_inputs(&mut self) {
+ /// The journal's entry limit is written in connected elements, so it has to follow the live
+ /// element count rather than a high-water mark.
+ pub(super) fn update_journal_entry_limit(&mut self) {
self.host
.journal
.set_document_entry_limit(self.retained.tree.connected_element_count());
diff --git a/Libraries/LibWeb/Rust/src/css/style/partial_view.rs b/Libraries/LibWeb/Rust/src/css/style/partial_view.rs
index 5f03665671e..a1d9332019d 100644
--- a/Libraries/LibWeb/Rust/src/css/style/partial_view.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/partial_view.rs
@@ -7,7 +7,7 @@
/// The result of consulting an optional physical materialization.
///
/// A known absence is a semantic answer. A missing result names the coverage gap that prevents an
-/// answer, so eviction can never silently turn unknown state into an empty relation.
+/// answer, so a gap can never silently turn unknown state into an empty relation.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum Lookup<T, Gap> {
Known(T),
diff --git a/Libraries/LibWeb/Rust/src/css/style/planning.rs b/Libraries/LibWeb/Rust/src/css/style/planning.rs
index 760f3ba2a17..6b14d1e3a90 100644
--- a/Libraries/LibWeb/Rust/src/css/style/planning.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/planning.rs
@@ -190,9 +190,7 @@ impl RetainedState {
}
visit(node);
- let previous_capacity = pending.capacity();
pending.extend(self.tree.flat_tree_children(node));
- if pending.capacity() > previous_capacity {}
}
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/prefix.rs b/Libraries/LibWeb/Rust/src/css/style/prefix.rs
index 78ffdad86fb..38d7016c1fa 100644
--- a/Libraries/LibWeb/Rust/src/css/style/prefix.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/prefix.rs
@@ -1237,7 +1237,7 @@ impl PrefixTransitionContexts {
/// Prepare one program's context again when the arena it was prepared against was replaced.
///
/// A traversal owns its contexts for as long as it runs, while the states they name can be
- /// released and rebuilt under it whenever the cache loses its residency. Every pairing of a
+ /// released and rebuilt under it whenever the cache is released. Every pairing of a
/// context with an arena therefore revalidates before reading memoized answers.
pub(super) fn rebind(&mut self, program: ScopeProgramID, states: &mut PrefixStates, facts: &StyleNodeFacts) {
let context = self
@@ -1258,7 +1258,6 @@ impl PrefixTransitionContexts {
}
pub(super) fn install(&mut self, states: &mut PrefixStateCache) {
- let mut installed = false;
for (program, context) in self.by_program.iter_mut().enumerate() {
if let Some(context) = context
&& !context.effects.writes.is_empty()
@@ -1267,10 +1266,8 @@ impl PrefixTransitionContexts {
))
{
states.install_prefix_effects(&mut context.effects);
- installed = true;
}
}
- if installed {}
}
}
@@ -3970,7 +3967,7 @@ impl PrefixStates {
}
/// Shed unreachable interned identities and allocation slack before the working form is
- /// offered for residency. Only per-element transitions cross this boundary; traversal memos
+ /// retained. Only per-element transitions cross this boundary; traversal memos
/// and completed-answer keys are batch-local, so every remapped identity stays internal.
fn trim_for_retention(&mut self) {
let working_bytes = self.interned_working_bytes();
@@ -4283,7 +4280,7 @@ fn selected_matches_equal(left: &[EntryID], right: &[EntryID], selection: &Prefi
/// Prefix states shared by every element ask in one synchronous matching traversal.
///
/// The delta representation keeps the working form small enough to retain outright, so there is
-/// no compact retained encoding. Retention moves the same working bytes from scratch into Tier 3.
+/// no compact retained encoding. Retention keeps the same working form.
pub(super) struct PrefixStateCache {
by_program: Column<Option<Box<PrefixStates>>>,
lifecycle: PrefixStateCacheLifecycle,
@@ -4397,9 +4394,9 @@ impl PrefixStateCache {
};
}
- pub(super) fn retain(&mut self) -> bool {
+ pub(super) fn retain(&mut self) {
if self.lifecycle.is_retained() {
- return true;
+ return;
}
for states in self.by_program.iter_mut().flatten() {
states.trim_for_retention();
@@ -4410,7 +4407,6 @@ impl PrefixStateCache {
PrefixStateCacheLifecycle::CurrentScratch(coverage) => PrefixStateCacheLifecycle::CurrentRetained(coverage),
PrefixStateCacheLifecycle::Retained(_) | PrefixStateCacheLifecycle::CurrentRetained(_) => unreachable!(),
};
- true
}
/// Forget one element's transition. This is the whole maintenance a pure tree flush needs,
@@ -4787,7 +4783,7 @@ mod tests {
});
}
- // Losing residency rebuilds the arena every answer above names by index.
+ // Releasing the cache rebuilds the arena every answer above names by index.
let mut rebuilt = PrefixStates::new();
contexts.rebind(program, &mut rebuilt, &facts);
let context = contexts.get_mut(program);
@@ -5421,27 +5417,4 @@ mod tests {
]
);
}
-
- #[test]
- fn retained_cache_entry_maintenance_charges_the_residency_lease() {
- use super::super::index::StateSet;
-
- let mut cache = PrefixStateCache::default();
- let mut facts = StyleNodeFacts::new();
- facts.push_row(
- super::super::tree::StyleNodeID::element(1),
- StyleAtomID(1),
- StyleAtomID::NONE,
- StateSet(0),
- &[],
- &[],
- );
- let mut context = PrefixTransitionContext::new(cache.prepare_program(ScopeProgramID(0)), &facts);
-
- assert!(cache.retain());
-
- // Preparing a fresh private row domain does not change retained cache accounting.
- context.scratch.prepare_rows(facts.generation() + 1);
- let _ = cache.prepare_program(ScopeProgramID(0));
- }
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/program_updates.rs b/Libraries/LibWeb/Rust/src/css/style/program_updates.rs
index dd0c72090d0..d51d4ae39a6 100644
--- a/Libraries/LibWeb/Rust/src/css/style/program_updates.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/program_updates.rs
@@ -130,10 +130,9 @@ impl RetainedState {
/// Intern one immutable specified value into the rule program's dense value table.
pub fn intern_specified_value(&mut self, value: &Arc<StyleValueData>) -> SpecifiedValueID {
- let (id, lookup) = self.specified_values.intern(value);
- match lookup {
- Lookup::Known(()) => self.counters.bump(Counter::SpecifiedValuesReused),
- Lookup::KnownAbsent | Lookup::Missing(_) => {}
+ let (id, reused) = self.specified_values.intern(value);
+ if reused {
+ self.counters.bump(Counter::SpecifiedValuesReused);
}
id
}
@@ -1349,7 +1348,7 @@ impl StyleEngine {
/// Take the pending transaction for the style consumer that immediately follows this call.
///
/// Exact planning may already have packed the current facts and built document-order
- /// coordinates. Keep that Tier-4 workspace for matching instead of reconstructing it. The
+ /// coordinates. Keep that workspace for matching instead of reconstructing it. The
/// callback receives only accepted match-answer records after their complete payloads have been
/// published. Versions are shared by the whole emitted batch rather than repeated per record.
#[cfg(test)]
diff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rs
index f38c64d27e2..561d39fb7c7 100644
--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs
@@ -294,7 +294,7 @@ impl RetainedState {
if !Self::retained_store_supports_property(target, winner.property) {
return None;
}
- let Lookup::Known(value) = self.specified_values.retained_value(winner.key.value) else {
+ let Some(value) = self.specified_values.retained_value(winner.key.value) else {
return None;
};
if crate::css::style_compute::external_value_dependencies(value.data())
@@ -457,8 +457,8 @@ impl RetainedState {
Ok(delta)
}
- /// The winners a driven element's record is computed from. A republish admits the row whatever
- /// the memory budget, and an answer that published nothing is matched again; a row that holds
+ /// The winners a driven element's record is computed from. An answer that published nothing is
+ /// matched again; a row that holds
/// no winners even then is the host's, as is one a drive without the leave to republish holds
/// no winners for.
fn driven_element_winners(
@@ -1350,7 +1350,6 @@ impl RetainedState {
);
}
}
- self.mark_published_answer_observed(node);
}
/// The records the engine derived for `node`'s element that the host has not taken, for the
@@ -1911,9 +1910,10 @@ impl RetainedState {
self.winner_groups
.winner_in_state(state, crate::css::property_metadata::property_id::FONT_FAMILY)
.and_then(|winner| self.winner_groups.resolved_winner(winner))
- .is_some_and(|winner| match self.specified_values.value(winner.key.value) {
- Lookup::Known(data) => crate::css::style_compute::font_family_is_monospace(data),
- _ => true,
+ .is_some_and(|winner| {
+ self.specified_values
+ .value(winner.key.value)
+ .is_none_or(crate::css::style_compute::font_family_is_monospace)
})
}
@@ -2939,7 +2939,7 @@ impl RetainedState {
if facts & bridge::element_adjustment_fact::HAS_ANIMATIONS != 0 {
return;
}
- // A state minted before the winner groups were evicted names nothing in the table now.
+ // A state minted before the winner groups were cleared names nothing in the table now.
if cascade_state.0 != self.winner_groups.generation() {
return;
}
@@ -4211,8 +4211,8 @@ impl StyleEngine {
/// Frees what the engine kept for the leases of published frames, once none is held. The host calls it as it
/// takes a recording in, so that a document that styles nothing more still frees what its recording kept.
pub(crate) fn free_style_records_kept_for_leases(&mut self) {
- let freed_overlays = self.retained.computed_group_sets.free_retired_animation_overlays();
- if self.reclaim_unreachable_computed_records() || freed_overlays {}
+ self.retained.computed_group_sets.free_retired_animation_overlays();
+ self.reclaim_unreachable_computed_records();
}
/// Reclaims the unreachable computed records, if they are due and nothing views them, and answers whether it did.
@@ -5418,39 +5418,6 @@ mod tests {
}
}
- #[test]
- fn acknowledgement_without_pending_records_observes_published_answer() {
- let mut engine = StyleEngine::new();
- let mut raw_nodes = [0; 2];
- engine.allocate_style_nodes(&mut raw_nodes);
- let [first, second] = raw_nodes.map(|node| StyleNodeID::from_raw(node).unwrap());
- for node in [first, second] {
- engine.retained.published_match_answers.push(
- PublishedMatchAnswer {
- node,
- cascade_input: None,
- matches: None,
- cascade_winners_are_complete: true,
- observed: false,
- },
- &engine.retained.counters,
- );
- }
- engine.published_match_answers.sort();
- assert!(engine.engine_computed_records_pending.is_empty());
-
- engine.acknowledge_engine_computed_record(second);
- let effects = std::mem::take(&mut engine.published_match_answers.answer_effects);
- engine.install_answer_effects(effects);
- assert!(engine.published_match_answers.lookup(second).unwrap().observed);
- assert!(!engine.published_match_answers.lookup(first).unwrap().observed);
- engine.acknowledge_engine_computed_record(second);
- let effects = std::mem::take(&mut engine.published_match_answers.answer_effects);
- engine.install_answer_effects(effects);
- assert!(engine.published_match_answers.lookup(second).unwrap().observed);
- assert_eq!(engine.counters.get(Counter::EngineComputedLonghandEvaluations), 0);
- }
-
#[test]
fn pending_records_acknowledge_and_rollback_independently_by_node() {
let mut engine = StyleEngine::new();
diff --git a/Libraries/LibWeb/Rust/src/css/style/publication/demand.rs b/Libraries/LibWeb/Rust/src/css/style/publication/demand.rs
index 5c887cd0c27..f5447f44e6e 100644
--- a/Libraries/LibWeb/Rust/src/css/style/publication/demand.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/publication/demand.rs
@@ -300,7 +300,6 @@ impl StyleEngine {
cascade_input: answer.cascade_input,
matches: answer.matches.clone(),
cascade_winners_are_complete: answer.cascade_winners_are_complete,
- observed: false,
},
&self.retained.counters,
);
diff --git a/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs b/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs
index 6521078006c..75d2139f484 100644
--- a/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs
@@ -100,7 +100,7 @@ impl RetainedState {
}
let republication = republication.or_refused()?;
// The element row may already be compared with the record derived from it in this flush:
- // keep it and publish only the pseudo rows. An evicted answer is matched again.
+ // keep it and publish only the pseudo rows. A missing answer is matched again.
let republished = self.current_winner_groups().row_stamp(node) == Some(self.flush_stamp)
&& self
.republish_pseudo_winners_from_retained_answer(node, republication)
@@ -739,8 +739,8 @@ impl RetainedState {
}
}
- /// The kinds the node's match answer has rules for, matching the element again when that
- /// answer was evicted. A match that cannot complete for want of a fact generates no
+ /// The kinds the node's match answer has rules for, matching the element again when there is
+ /// no answer. A match that cannot complete for want of a fact generates no
/// pseudo-element.
pub(super) fn pseudo_style_mask_or_rematch(&mut self, node: StyleNodeID) -> u64 {
if let Some(mask) = self.pseudo_style_mask(node) {
diff --git a/Libraries/LibWeb/Rust/src/css/style/routing.rs b/Libraries/LibWeb/Rust/src/css/style/routing.rs
index b8b81d902c1..47f361e910a 100644
--- a/Libraries/LibWeb/Rust/src/css/style/routing.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/routing.rs
@@ -3823,8 +3823,7 @@ impl RetainedState {
// Once both exact fact sides and the retained answer are complete, their region union can
// be compared by evaluating that entry once per candidate. This replaces repeated partial
// path walks with the exact question the planner ultimately needs to answer. Keep initial
- // and incomplete state on the original route-order path: its allocation lifetimes are part
- // of retained-cache admission under memory pressure.
+ // and incomplete state on the original route-order path.
let can_group_exact_entries = retained_winners_are_current
&& transaction.inputs.iter().all(|input| {
let (InputKey::LocalFeature(node, _) | InputKey::State(node, _)) = input.key else {
diff --git a/Libraries/LibWeb/Rust/src/css/style/selector.rs b/Libraries/LibWeb/Rust/src/css/style/selector.rs
index 4e8d90c98f0..372699917f1 100644
--- a/Libraries/LibWeb/Rust/src/css/style/selector.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/selector.rs
@@ -4039,9 +4039,9 @@ fn state_is_published_on_arrival(fact: StateFact) -> bool {
/// Maps each semantic input key to the canonical transpose routes that mention it.
///
-/// This is required program state, not an evictable view. Scanning every selector header for every
+/// This is required program state, not an optional view. Scanning every selector header for every
/// ordinary mutation would change the hot path's asymptotics, so routing has to be an index.
-/// Feature postings may accelerate subject enumeration on top of it, but evicting a posting never
+/// Feature postings may accelerate subject enumeration on top of it, but a missing posting never
/// changes which routes run.
const LIVENESS_LOCK: &str = "the routing liveness view is never held across a panic";
diff --git a/Libraries/LibWeb/Rust/src/css/style/specified_value.rs b/Libraries/LibWeb/Rust/src/css/style/specified_value.rs
index 02ccb0d5899..a2e3a3fe589 100644
--- a/Libraries/LibWeb/Rust/src/css/style/specified_value.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/specified_value.rs
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-//! Canonical specified-value identities retained as an evictable dense table.
+//! Canonical specified-value identities retained as a dense table.
use crate::css::style_value::RetainedStyleValueData;
use crate::css::style_value::StyleValueData;
@@ -12,7 +12,6 @@ use std::sync::Arc;
use super::cascade::SpecifiedValueID;
use super::fast_hash::FastMap as HashMap;
-use super::partial_view::Lookup;
#[derive(Clone)]
@@ -29,20 +28,12 @@ impl super::intern_table::InternIdentity for SpecifiedValueEntryIndex {
}
}
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub(super) enum SpecifiedValueGap {
- RetiredPayloads { eviction_generation: u64 },
-}
-
-/// An identity is never reused, so evicting the values only makes future equality checks
-/// conservative. Existing rule and winner rows can keep comparing their opaque identities without
-/// retaining old CSSOM values forever.
+/// An identity is never reused, so rule and winner rows can compare their opaque identities.
#[derive(Clone)]
pub(super) struct SpecifiedValues {
entries: super::intern_table::InternTable<SpecifiedValueEntryIndex, SpecifiedValueEntry>,
entries_by_pointer: HashMap<usize, SpecifiedValueID>,
entries_by_id: HashMap<SpecifiedValueID, u32>,
- gap: Option<SpecifiedValueGap>,
next_id: u64,
}
@@ -52,15 +43,14 @@ impl SpecifiedValues {
entries: super::intern_table::InternTable::default(),
entries_by_pointer: HashMap::default(),
entries_by_id: HashMap::default(),
- gap: None,
next_id: 1,
}
}
#[must_use]
- fn lookup(&self, value: &StyleValueData) -> Lookup<SpecifiedValueID, SpecifiedValueGap> {
+ fn lookup(&self, value: &StyleValueData) -> Option<SpecifiedValueID> {
if let Some(id) = self.entries_by_pointer.get(&(std::ptr::from_ref(value) as usize)) {
- return Lookup::Known(*id);
+ return Some(*id);
}
// Equal URL text can refer to different resources in different declarations. The native
// image keeps its stylesheet context outside StyleValueData, so only an existing pointer
@@ -70,65 +60,46 @@ impl SpecifiedValues {
.entries
.find(value.content_hash(), |_index, entry| entry.value.data() == value)
{
- return Lookup::Known(self.entries[index].id);
+ return Some(self.entries[index].id);
}
- self.gap.map_or(Lookup::KnownAbsent, Lookup::Missing)
- }
-
- fn mark_partial(&mut self) -> SpecifiedValueGap {
- *self
- .gap
- .get_or_insert(SpecifiedValueGap::RetiredPayloads { eviction_generation: 1 })
+ None
}
/// Return the retained payload behind one maintained declaration identity.
#[must_use]
- pub(super) fn value(&self, id: SpecifiedValueID) -> Lookup<&StyleValueData, SpecifiedValueGap> {
- if let Some(index) = self.entries_by_id.get(&id) {
- return Lookup::Known(self.entries[*index as usize].value.data());
- }
- self.gap.map_or(Lookup::KnownAbsent, Lookup::Missing)
+ pub(super) fn value(&self, id: SpecifiedValueID) -> Option<&StyleValueData> {
+ let index = self.entries_by_id.get(&id)?;
+ Some(self.entries[*index as usize].value.data())
}
/// Return an owned reference to one maintained declaration payload.
#[must_use]
#[cfg(test)]
- pub(super) fn retained_value(&self, id: SpecifiedValueID) -> Lookup<RetainedStyleValueData, SpecifiedValueGap> {
- if let Some(index) = self.entries_by_id.get(&id) {
- return Lookup::Known(self.entries[*index as usize].value.clone_retained());
- }
- self.gap.map_or(Lookup::KnownAbsent, Lookup::Missing)
+ pub(super) fn retained_value(&self, id: SpecifiedValueID) -> Option<RetainedStyleValueData> {
+ let index = self.entries_by_id.get(&id)?;
+ Some(self.entries[*index as usize].value.clone_retained())
}
- pub(super) fn intern(&mut self, value: &Arc<StyleValueData>) -> (SpecifiedValueID, Lookup<(), SpecifiedValueGap>) {
- let lookup = match self.lookup(value) {
- Lookup::Known(id) => return (id, Lookup::Known(())),
- Lookup::KnownAbsent => Lookup::KnownAbsent,
- Lookup::Missing(gap) => Lookup::Missing(gap),
- };
-
+ /// The identity of `value`, and whether it already had one.
+ pub(super) fn intern(&mut self, value: &Arc<StyleValueData>) -> (SpecifiedValueID, bool) {
+ if let Some(id) = self.lookup(value) {
+ return (id, true);
+ }
let id = SpecifiedValueID(self.next_id);
self.next_id = self
.next_id
.checked_add(1)
.expect("specified value identity space exhausted");
- if !true {
- return (id, Lookup::Missing(self.mark_partial()));
- }
self.push_entry(id, RetainedStyleValueData::from_arc(Arc::clone(value)));
-
- (id, lookup)
+ (id, false)
}
/// Associate another immutable spelling with an existing canonical identity.
pub(super) fn alias(&mut self, value: &Arc<StyleValueData>, id: SpecifiedValueID) {
- if let Lookup::Known(existing) = self.lookup(value) {
+ if let Some(existing) = self.lookup(value) {
debug_assert_eq!(existing, id);
return;
}
- if !true {
- return;
- }
self.push_entry(id, RetainedStyleValueData::from_arc(Arc::clone(value)));
}
@@ -177,13 +148,9 @@ mod tests {
let (canonical_id, _) = values.intern(&canonical);
values.alias(&authored, canonical_id);
assert_eq!(values.entries_by_pointer.len(), 2);
- assert!(matches!(
- values.lookup(&authored),
- Lookup::Known(id) if id == canonical_id
- ));
- let (authored_id, lookup) = values.intern(&authored);
-
+ assert_eq!(values.lookup(&authored), Some(canonical_id));
+ let (authored_id, reused) = values.intern(&authored);
assert_eq!(authored_id, canonical_id);
- assert!(matches!(lookup, Lookup::Known(())));
+ assert!(reused);
}
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/tests.rs b/Libraries/LibWeb/Rust/src/css/style/tests.rs
index ec7e3295498..ec169a68160 100644
--- a/Libraries/LibWeb/Rust/src/css/style/tests.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/tests.rs
@@ -807,7 +807,6 @@ fn published_match_answer(node: u32, cascade_input: Option<u32>, match_count: us
cascade_input: cascade_input.map(MatchAnswerID),
matches: Some(vec![rule_match; match_count].into_boxed_slice()),
cascade_winners_are_complete: true,
- observed: false,
}
}
@@ -1091,7 +1090,7 @@ fn an_evicted_prefix_answer_is_a_typed_missing_key() {
};
answers.remember(&mut catalog, key, &[], None, None, MatchAnswerID(1), true);
- assert!(answers.retain());
+ answers.retain();
assert!(matches!(
answers.lookup(key),
Lookup::Known(answer)
@@ -1101,7 +1100,7 @@ fn an_evicted_prefix_answer_is_a_typed_missing_key() {
answers.make_scratch();
assert!(matches!(answers.lookup(key), Lookup::Known(_)));
- assert!(answers.retain());
+ answers.retain();
answers.release(&mut catalog);
assert!(catalog.answer(contribution).is_none());
@@ -1181,7 +1180,7 @@ fn prefix_answer_keys_compare_content_after_hash_collisions() {
assert_eq!(answers.lookup(key).sparse().unwrap().cascade_input, MatchAnswerID(100));
}
- assert!(answers.retain());
+ answers.retain();
answers.release(&mut catalog);
assert!(catalog.answer(contribution).is_none());
@@ -1388,7 +1387,7 @@ fn retained_match_answer_payloads_are_evictable_without_losing_identity() {
assert_eq!(catalog.intern(&[same_retained_match]), identity);
answers.remember_cascade_input(&mut catalog, node, cascade_input);
- answers.evict(&mut catalog);
+ answers.clear(&mut catalog);
assert!(catalog.retained_answer(identity).is_none());
assert!(matches!(answers.lookup(node), Lookup::Missing(gap) if gap == node));
assert!(matches!(
@@ -1598,7 +1597,7 @@ fn an_evicted_feature_posting_is_missing_instead_of_empty() {
let key = SelectorPostingKey::Class(target);
assert!(matches!(engine.facts.postings().lookup(key), Lookup::Known(_)));
- engine.facts.postings_mut().evict(key);
+ engine.facts.postings_mut().drop_posting(key);
assert!(matches!(engine.facts.postings().lookup(key), Lookup::Missing(gap) if gap == key));
remove_feature(&mut engine, nodes[1], LocalFeatureKey::Class(guard));
@@ -2906,7 +2905,10 @@ fn hover_requires_style_state_only_when_an_origin_may_be_present() {
discard_transaction(&mut engine);
assert!(!engine.hover_needs_style_state(nodes[0]));
- engine.facts.postings_mut().evict(SelectorPostingKey::Class(second));
+ engine
+ .facts
+ .postings_mut()
+ .drop_posting(SelectorPostingKey::Class(second));
assert!(engine.hover_needs_style_state(nodes[0]));
}
@@ -3562,7 +3564,7 @@ fn an_evicted_retained_match_answer_falls_back_to_cold_matching() {
engine
.retained
.retained_match_answers
- .evict(&mut engine.retained.match_answers);
+ .clear(&mut engine.retained.match_answers);
assert!(matches!(
engine.retained_match_answer(nodes[1]),
Lookup::Missing(gap) if gap == nodes[1]
@@ -3647,7 +3649,7 @@ fn an_evicted_answer_payload_repairs_to_its_retained_identity() {
engine
.retained
.retained_match_answers
- .evict(&mut engine.retained.match_answers);
+ .clear(&mut engine.retained.match_answers);
engine.set_rule_conditions_hold(losing_rule, false);
let repairs_before = engine.counters().get(Counter::PublishedMatchAnswerIdentityRepairs);
diff --git a/Libraries/LibWeb/Rust/src/css/style/tree.rs b/Libraries/LibWeb/Rust/src/css/style/tree.rs
index ebdf467b0cd..6c3d5c67fa2 100644
--- a/Libraries/LibWeb/Rust/src/css/style/tree.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/tree.rs
@@ -773,7 +773,7 @@ impl StyleNodeTree {
tree
}
- /// Connected styleable elements, which is the count the document memory budget is written in.
+ /// Connected styleable elements, which is the count the journal's entry limit is written in.
#[must_use]
pub fn connected_element_count(&self) -> u32 {
self.connected_element_count
@@ -2845,7 +2845,7 @@ mod tests {
#[test]
fn per_node_relation_state_fits_the_mandatory_budget() {
// Rust stores four relation columns, depth, and the style-record handle per node. The DOM
- // owns the style-node identity mapping counted by the documented surface budget.
+ // owns the style-node identity mapping.
const STYLE_RECORD_ID_BYTES: usize = 4;
const STYLE_NODE_ID_BYTES: usize = 4;
let required = 4 * size_of::<Option<StyleNodeID>>() + size_of::<u32>() + STYLE_RECORD_ID_BYTES;
diff --git a/Libraries/LibWeb/Rust/src/css/style/weak_pool.rs b/Libraries/LibWeb/Rust/src/css/style/weak_pool.rs
index 56ae8825b7d..427ac4ffb01 100644
--- a/Libraries/LibWeb/Rust/src/css/style/weak_pool.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/weak_pool.rs
@@ -17,8 +17,7 @@ const MINIMUM_SWEEP_THRESHOLD: usize = 64;
/// while something is interned through it.
/// A dead reference still holds its value's allocation, though not the value, until it is dropped
/// when its bucket is next searched or by a full sweep, which runs whenever the references have
-/// doubled since the last one, so dead references never outnumber the live ones by much. Shared
-/// values are charged once to the pool's own ledger.
+/// doubled since the last one, so dead references never outnumber the live ones by much.
pub(super) struct WeakPool<T> {
by_hash: HashMap<u64, Vec<Weak<T>>>,
references: usize,
diff --git a/Tests/LibWeb/Text/input/css/style-engine/factorized-operator-document-scale.html b/Tests/LibWeb/Text/input/css/style-engine/factorized-operator-document-scale.html
index 80214af9177..157072a9659 100644
--- a/Tests/LibWeb/Text/input/css/style-engine/factorized-operator-document-scale.html
+++ b/Tests/LibWeb/Text/input/css/style-engine/factorized-operator-document-scale.html
@@ -20,12 +20,11 @@
];
function difference(after, before, names) {
- // Residency gauges scale with the document, phase clocks measure elapsed time,
- // and the catalog mint counts measure how warm the catalogs are: the first
- // measurement mints the identities every later one reuses. None of the three is
- // deterministic physical work held to this invariant.
- const measured = names.filter(name => !name.startsWith("tier3Resident")
- && !name.endsWith("Microseconds") && !name.endsWith("IdentitiesMinted"));
+ // Phase clocks measure elapsed time, and the catalog mint counts measure how warm
+ // the catalogs are: the first measurement mints the identities every later one
+ // reuses. Neither is deterministic physical work held to this invariant.
+ const measured = names.filter(name => !name.endsWith("Microseconds")
+ && !name.endsWith("IdentitiesMinted"));
return Object.fromEntries(measured.map(name => [name, after[name] - before[name]]));
}