Skip to content

Truly independent web browser

LibWeb: Keep style bookkeeping from copying tables a fork shares

Tim Ledbettere3db9825a8ca
diff --git a/Libraries/LibWeb/Rust/src/css/style/cascade.rs b/Libraries/LibWeb/Rust/src/css/style/cascade.rs
index 4dc0e62a17b..1b57f987fec 100644
--- a/Libraries/LibWeb/Rust/src/css/style/cascade.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/cascade.rs
@@ -1073,7 +1073,7 @@ impl WinnerEffects {
Some(1 + pseudos.len())
}
- pub(super) fn release_pending_all(self, groups: &mut WinnerGroups) {
+ pub(super) fn release_pending_all(self, groups: &mut crate::fork::ForkShared<WinnerGroups>) {
for write in self.writes {
if let WinnerNodeWrite::Set { state, .. } = write {
groups.release_pending(state);
diff --git a/Libraries/LibWeb/Rust/src/css/style/catalog.rs b/Libraries/LibWeb/Rust/src/css/style/catalog.rs
index 64ba28d15ca..f07fd855a1e 100644
--- a/Libraries/LibWeb/Rust/src/css/style/catalog.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/catalog.rs
@@ -1016,8 +1016,8 @@ impl AnswerEffects {
pub(super) fn release_pending_all(
self,
- catalog: &mut MatchAnswerCatalog,
- winners: &mut super::cascade::WinnerGroups,
+ catalog: &mut crate::fork::ForkShared<MatchAnswerCatalog>,
+ winners: &mut crate::fork::ForkShared<super::cascade::WinnerGroups>,
) {
self.winners.release_pending_all(winners);
for (_, entry) in self.entries {
diff --git a/Libraries/LibWeb/Rust/src/css/style/computed.rs b/Libraries/LibWeb/Rust/src/css/style/computed.rs
index 52ee0cb2023..e5b8e7968ac 100644
--- a/Libraries/LibWeb/Rust/src/css/style/computed.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/computed.rs
@@ -912,7 +912,6 @@ pub struct ComputedGroupSets {
pseudo_rows_by_node: crate::fork::ForkShared<HashMap<StyleNodeID, Box<[PseudoComputedRow]>>>,
style_records_interned_since_reclamation: usize,
next_reclamation_after: usize,
- style_record_view_epoch_depth: u32,
}
impl Default for ComputedGroupSets {
@@ -944,19 +943,11 @@ impl Default for ComputedGroupSets {
style_records_interned_since_reclamation: 0,
next_reclamation_after: 1024,
- style_record_view_epoch_depth: 0,
}
}
}
impl ComputedGroupSets {
- pub(crate) fn begin_style_record_view_epoch(&mut self) {
- self.style_record_view_epoch_depth = self
- .style_record_view_epoch_depth
- .checked_add(1)
- .expect("style-record view epoch depth overflow");
- }
-
pub(crate) fn lease_style_records(&self) -> StyleRecordLease {
self.leases.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
StyleRecordLease {
@@ -1035,14 +1026,6 @@ impl ComputedGroupSets {
std::mem::take(&mut self.released_animation_overlay_records)
}
- pub(crate) fn end_style_record_view_epoch(&mut self) {
- assert!(
- self.style_record_view_epoch_depth > 0,
- "style-record view epoch underflow"
- );
- self.style_record_view_epoch_depth -= 1;
- }
-
fn group_identities(&self, set: ComputedGroupSetID) -> impl Iterator<Item = ComputedGroupID> {
self.sets[set].groups.iter().copied()
}
@@ -3675,9 +3658,9 @@ impl ComputedGroupSets {
self.identity_mints
}
- pub(super) fn reclaim_unreachable_if_needed(&mut self) -> Option<ComputedGroupRetention> {
+ pub(super) fn reclaim_unreachable_if_needed(&mut self, records_are_viewed: bool) -> Option<ComputedGroupRetention> {
self.free_retired_animation_overlays();
- if self.style_record_view_epoch_depth != 0 || self.style_records_are_leased() {
+ if records_are_viewed || self.style_records_are_leased() {
return None;
}
if self.style_records_interned_since_reclamation < self.next_reclamation_after {
@@ -3868,7 +3851,6 @@ impl Clone for ComputedGroupSets {
pseudo_rows_by_node: self.pseudo_rows_by_node.clone(),
style_records_interned_since_reclamation: self.style_records_interned_since_reclamation,
next_reclamation_after: self.next_reclamation_after,
- style_record_view_epoch_depth: self.style_record_view_epoch_depth,
};
for identity in copy.groups.live_identities() {
let group = copy.groups.get(identity);
diff --git a/Libraries/LibWeb/Rust/src/css/style/inputs.rs b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
index 910a2b67a7c..3fc30157acc 100644
--- a/Libraries/LibWeb/Rust/src/css/style/inputs.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
@@ -2002,6 +2002,7 @@ impl StyleEngine {
specified_values: crate::fork::ForkShared::new(SpecifiedValues::new()),
winner_groups: crate::fork::ForkShared::new(WinnerGroups::new()),
computed_group_sets: Default::default(),
+ style_record_view_epoch_depth: 0,
custom_property_environments: Default::default(),
nodes_with_substituted_records: HashSet::default(),
custom_declaration_reads: HashMap::default(),
@@ -3376,6 +3377,7 @@ impl RetainedState {
specified_values: _,
winner_groups,
computed_group_sets,
+ style_record_view_epoch_depth: _,
custom_property_environments: _,
nodes_with_substituted_records,
custom_declaration_reads,
diff --git a/Libraries/LibWeb/Rust/src/css/style/mod.rs b/Libraries/LibWeb/Rust/src/css/style/mod.rs
index b40374a8233..69d60b9e9d3 100644
--- a/Libraries/LibWeb/Rust/src/css/style/mod.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/mod.rs
@@ -824,6 +824,8 @@ pub struct RetainedState {
/// computed half of the eventual base style record; custom properties and metadata remain
/// separate inputs until that record is complete.
computed_group_sets: crate::fork::ForkShared<ComputedGroupSets>,
+ /// How many epochs of style record views the host has open. No computed record is reclaimed while one is.
+ style_record_view_epoch_depth: u32,
/// The stores behind the custom-property environments live records are published with.
custom_property_environments: crate::fork::ForkShared<custom_property_environments::CustomPropertyEnvironments>,
/// The nodes whose engine-computed record substituted a custom property into a winner: what
diff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rs
index adceec81517..6ca4403ad7c 100644
--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs
@@ -4163,7 +4163,10 @@ impl RetainedState {
}
pub(crate) fn begin_style_record_view_epoch(&mut self) {
- self.computed_group_sets.begin_style_record_view_epoch();
+ self.style_record_view_epoch_depth = self
+ .style_record_view_epoch_depth
+ .checked_add(1)
+ .expect("style-record view epoch depth overflow");
}
/// Publishes how many identities each catalog has minted. These count the sharing partition
@@ -4379,7 +4382,12 @@ impl StyleEngine {
/// Reclaims the unreachable computed records, if they are due and nothing views them, and answers whether it did.
pub(super) fn reclaim_unreachable_computed_records(&mut self) -> bool {
- let Some(retention) = self.retained.computed_group_sets.reclaim_unreachable_if_needed() else {
+ let records_are_viewed = self.retained.style_record_view_epoch_depth != 0;
+ let Some(retention) = self
+ .retained
+ .computed_group_sets
+ .reclaim_unreachable_if_needed(records_are_viewed)
+ else {
return false;
};
self.retained
@@ -5991,7 +5999,11 @@ mod tests {
impl StyleEngine {
pub(crate) fn end_style_record_view_epoch(&mut self) {
- self.retained.computed_group_sets.end_style_record_view_epoch();
+ assert!(
+ self.retained.style_record_view_epoch_depth > 0,
+ "style-record view epoch underflow"
+ );
+ self.retained.style_record_view_epoch_depth -= 1;
self.reclaim_unreachable_computed_records();
}
}