Bug 1493507 - Avoid walking the rule tree three times from apply_declarations. r=xidorn
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 24 Sep 2018 08:42:15 +0000
changeset 493589 cf4cc2623a5b273ae0672ee83f83a72042652b77
parent 493588 96a7976274443cf4d876a526e8733395377aacae
child 493590 6f81edbb4e875c36873586cea21f5b3d5a1497f8
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1493507
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1493507 - Avoid walking the rule tree three times from apply_declarations. r=xidorn Just once is slow enough. Differential Revision: https://phabricator.services.mozilla.com/D6574
servo/components/style/properties/cascade.rs
--- a/servo/components/style/properties/cascade.rs
+++ b/servo/components/style/properties/cascade.rs
@@ -15,16 +15,17 @@ use properties::{LonghandId, LonghandIdS
 use properties::{PropertyDeclaration, PropertyDeclarationId, DeclarationImportanceIterator};
 use properties::CASCADE_PROPERTY;
 use rule_cache::{RuleCache, RuleCacheConditions};
 use rule_tree::{CascadeLevel, StrongRuleNode};
 use selector_parser::PseudoElement;
 use servo_arc::Arc;
 use shared_lock::StylesheetGuards;
 use smallbitvec::SmallBitVec;
+use smallvec::SmallVec;
 use std::borrow::Cow;
 use std::cell::RefCell;
 use style_adjuster::StyleAdjuster;
 use values::computed;
 
 /// We split the cascade in two phases: 'early' properties, and 'late'
 /// properties.
 ///
@@ -235,20 +236,22 @@ where
                 parent_style.unwrap(),
                 parent_style_ignoring_first_line.unwrap()
             ) ||
             parent_style.unwrap().pseudo() == Some(PseudoElement::FirstLine)
     );
 
     let inherited_style = parent_style.unwrap_or(device.default_computed_values());
 
+    let mut declarations = SmallVec::<[(&_, CascadeLevel); 32]>::new();
     let custom_properties = {
         let mut builder = CustomPropertiesBuilder::new(inherited_style.custom_properties());
 
-        for (declaration, _cascade_level) in iter_declarations() {
+        for (declaration, cascade_level) in iter_declarations() {
+            declarations.push((declaration, cascade_level));
             if let PropertyDeclaration::Custom(ref declaration) = *declaration {
                 builder.cascade(&declaration.name, &declaration.value);
             }
         }
 
         builder.build()
     };
 
@@ -273,17 +276,17 @@ where
         quirks_mode,
         rule_cache_conditions: RefCell::new(rule_cache_conditions),
     };
 
     let using_cached_reset_properties = {
         let mut cascade = Cascade::new(&mut context, cascade_mode);
 
         cascade
-            .apply_properties::<EarlyProperties, I>(ApplyResetProperties::Yes, iter_declarations());
+            .apply_properties::<EarlyProperties, _>(ApplyResetProperties::Yes, declarations.iter().cloned());
 
         cascade.compute_visited_style_if_needed(
             element,
             parent_style,
             parent_style_ignoring_first_line,
             layout_parent_style,
             guards,
         );
@@ -292,17 +295,17 @@ where
             cascade.try_to_use_cached_reset_properties(rule_cache, guards);
 
         let apply_reset = if using_cached_reset_properties {
             ApplyResetProperties::No
         } else {
             ApplyResetProperties::Yes
         };
 
-        cascade.apply_properties::<LateProperties, I>(apply_reset, iter_declarations());
+        cascade.apply_properties::<LateProperties, _>(apply_reset, declarations.iter().cloned());
 
         using_cached_reset_properties
     };
 
     context.builder.clear_modified_reset();
 
     if matches!(cascade_mode, CascadeMode::Unvisited { .. }) {
         StyleAdjuster::new(&mut context.builder)