style: Share CascadeData instances across ShadowRoots

This should be both a memory and speed win for pages using a lot of
Shadow DOM.

In order to make the cache properly work we need to start keying media query
results on the actual StyleSheetContents, as that's what we share on Gecko, but
that should all be fine.

Differential Revision: https://phabricator.services.mozilla.com/D107266
This commit is contained in:
Oriol Brufau 2023-05-16 09:51:46 +02:00
parent 11153c63fa
commit 060d74ba3b
11 changed files with 175 additions and 178 deletions

View file

@ -420,7 +420,7 @@ macro_rules! sheet_set_methods {
) {
debug!(concat!($set_name, "::append_stylesheet"));
self.collect_invalidations_for(device, &sheet, guard);
let collection = self.collection_for(&sheet, guard);
let collection = self.collection_for(&sheet);
collection.append(sheet);
}
@ -435,7 +435,7 @@ macro_rules! sheet_set_methods {
debug!(concat!($set_name, "::insert_stylesheet_before"));
self.collect_invalidations_for(device, &sheet, guard);
let collection = self.collection_for(&sheet, guard);
let collection = self.collection_for(&sheet);
collection.insert_before(sheet, &before_sheet);
}
@ -449,7 +449,7 @@ macro_rules! sheet_set_methods {
debug!(concat!($set_name, "::remove_stylesheet"));
self.collect_invalidations_for(device, &sheet, guard);
let collection = self.collection_for(&sheet, guard);
let collection = self.collection_for(&sheet);
collection.remove(&sheet)
}
@ -499,7 +499,7 @@ macro_rules! sheet_set_methods {
RuleChangeKind::StyleRuleDeclarations => DataValidity::FullyInvalid,
};
let collection = self.collection_for(&sheet, guard);
let collection = self.collection_for(&sheet);
collection.set_data_validity_at_least(validity);
}
};
@ -517,12 +517,8 @@ where
}
}
fn collection_for(
&mut self,
sheet: &S,
guard: &SharedRwLockReadGuard,
) -> &mut SheetCollection<S> {
let origin = sheet.origin(guard);
fn collection_for(&mut self, sheet: &S) -> &mut SheetCollection<S> {
let origin = sheet.contents().origin;
self.collections.borrow_mut_for_origin(&origin)
}
@ -670,11 +666,7 @@ where
self.collection.len()
}
fn collection_for(
&mut self,
_sheet: &S,
_guard: &SharedRwLockReadGuard,
) -> &mut SheetCollection<S> {
fn collection_for(&mut self, _sheet: &S) -> &mut SheetCollection<S> {
&mut self.collection
}