diff options
author | Oriol Brufau <obrufau@igalia.com> | 2023-05-16 23:20:00 +0200 |
---|---|---|
committer | Oriol Brufau <obrufau@igalia.com> | 2023-05-16 23:40:23 +0200 |
commit | e23a8bf0ad5fcfc23395b74dccb571fe360ee0bb (patch) | |
tree | 29d93077cab51f4c297482cb7f2fa9afbaf2dced /components/style/bloom.rs | |
parent | a7ca8022d3db119a77afdba6bdb70b82a90c58ac (diff) | |
download | servo-e23a8bf0ad5fcfc23395b74dccb571fe360ee0bb.tar.gz servo-e23a8bf0ad5fcfc23395b74dccb571fe360ee0bb.zip |
style: Add attribute names to the bloom filter
Safari does this. This reduces the runtime in the example linked from
comment 0 quite a lot (40ms on a local opt build, from ~130ms on a
release nightly build).
I added a pref because there's a slight chance of performance
regressions on pages that do not use attribute selectors, as we're now
doing more unconditional work per element (adding the attributes to the
bloom filter). But the trade-off should be worth it, I think.
Differential Revision: https://phabricator.services.mozilla.com/D111689
Diffstat (limited to 'components/style/bloom.rs')
-rw-r--r-- | components/style/bloom.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/components/style/bloom.rs b/components/style/bloom.rs index c17b31d1bee..d75abaa4f93 100644 --- a/components/style/bloom.rs +++ b/components/style/bloom.rs @@ -102,6 +102,15 @@ impl<E: TElement> PushedElement<E> { } } +/// Returns whether the attribute name is excluded from the bloom filter. +/// +/// We do this for attributes that are very common but not commonly used in +/// selectors. +#[inline] +pub fn is_attr_name_excluded_from_filter(atom: &crate::Atom) -> bool { + *atom == atom!("class") || *atom == atom!("id") || *atom == atom!("style") +} + fn each_relevant_element_hash<E, F>(element: E, mut f: F) where E: TElement, @@ -115,6 +124,14 @@ where } element.each_class(|class| f(class.get_hash())); + + if static_prefs::pref!("layout.css.bloom-filter-attribute-names.enabled") { + element.each_attr_name(|name| { + if !is_attr_name_excluded_from_filter(name) { + f(name.get_hash()) + } + }); + } } impl<E: TElement> Drop for StyleBloom<E> { |