Auto merge of #18497 - emilio:no-cache-if-cached, r=heycam

style: Don't cache styles that got a cache hit on the second pass.

This avoids doing wasted work, at least in the recascade case, and pretty likely
in the other as well.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18497)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-09-14 05:23:09 -05:00 committed by GitHub
commit 988728e9d5
2 changed files with 22 additions and 15 deletions

View file

@ -82,6 +82,7 @@ use smallvec::SmallVec;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::mem; use std::mem;
use std::ops::Deref; use std::ops::Deref;
use style_resolver::PrimaryStyle;
use stylist::Stylist; use stylist::Stylist;
mod checks; mod checks;
@ -546,11 +547,18 @@ impl<E: TElement> StyleSharingCache<E> {
/// ///
/// NB: We pass a source for the validation data, rather than the data itself, /// NB: We pass a source for the validation data, rather than the data itself,
/// to avoid memmoving at each function call. See rust issue #42763. /// to avoid memmoving at each function call. See rust issue #42763.
pub fn insert_if_possible(&mut self, pub fn insert_if_possible(
&mut self,
element: &E, element: &E,
style: &ComputedValues, style: &PrimaryStyle,
validation_data_holder: Option<&mut StyleSharingTarget<E>>, validation_data_holder: Option<&mut StyleSharingTarget<E>>,
dom_depth: usize) { dom_depth: usize,
) {
if style.0.reused_via_rule_node {
debug!("Failing to insert into the cached: this was a cached style");
return;
}
let parent = match element.traversal_parent() { let parent = match element.traversal_parent() {
Some(element) => element, Some(element) => element,
None => { None => {
@ -583,7 +591,7 @@ impl<E: TElement> StyleSharingCache<E> {
// //
// These are things we don't check in the candidate match because they // These are things we don't check in the candidate match because they
// are either uncommon or expensive. // are either uncommon or expensive.
let box_style = style.get_box(); let box_style = style.style().get_box();
if box_style.specifies_transitions() { if box_style.specifies_transitions() {
debug!("Failing to insert to the cache: transitions"); debug!("Failing to insert to the cache: transitions");
return; return;

View file

@ -678,11 +678,9 @@ where
resolver.resolve_style_with_default_parents() resolver.resolve_style_with_default_parents()
}; };
context.thread_local context.thread_local.sharing_cache.insert_if_possible(
.sharing_cache
.insert_if_possible(
&element, &element,
new_styles.primary.style(), &new_styles.primary,
Some(&mut target), Some(&mut target),
traversal_data.current_dom_depth, traversal_data.current_dom_depth,
); );
@ -724,9 +722,10 @@ where
resolver.cascade_styles_with_default_parents(cascade_inputs) resolver.cascade_styles_with_default_parents(cascade_inputs)
}; };
context.thread_local.sharing_cache.insert_if_possible( context.thread_local.sharing_cache.insert_if_possible(
&element, &element,
new_styles.primary.style(), &new_styles.primary,
None, None,
traversal_data.current_dom_depth, traversal_data.current_dom_depth,
); );