Skip to content

Commit

Permalink
Rewrite the style sharing candidate cache.
Browse files Browse the repository at this point in the history
The style candidate cache had regressed a few times (see #12534), and my
intuition is that being able to disable all style sharing with a single rule in
the page is really unfortunate.

This commit redesigns the style sharing cache in order to be a optimistic cache,
but then reject candidates if they match different sibling-affecting selectors
in the page, for example.

So far the numbers have improved, but not so much as I'd wanted (~10%/20% of
non-incremental restyling time in general). The current implementation is really
dumb though (we recompute and re-match a lot of stuff), so we should be able to
optimise it quite a bit.

I have different ideas for improving it (that may or may not work), apart of the
low-hanging fruit like don't re-matching candidates all the time but I have to
measure the real impact.

Also, I need to verify it against try.
  • Loading branch information
emilio committed Aug 17, 2016
1 parent ec53136 commit 3af774b
Show file tree
Hide file tree
Showing 23 changed files with 462 additions and 231 deletions.
2 changes: 1 addition & 1 deletion components/layout/Cargo.toml
Expand Up @@ -33,7 +33,7 @@ range = {path = "../range"}
rustc-serialize = "0.3"
script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
selectors = {version = "0.8", features = ["heap_size"]}
selectors = {version = "0.9", features = ["heap_size"]}
serde_macros = "0.8"
smallvec = "0.1"
string_cache = {version = "0.2.23", features = ["heap_size"]}
Expand Down
6 changes: 5 additions & 1 deletion components/layout/traversal.rs
Expand Up @@ -13,7 +13,7 @@ use gfx::display_list::OpaqueNode;
use script_layout_interface::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, RestyleDamage};
use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode};
use std::mem;
use style::context::SharedStyleContext;
use style::context::{LocalStyleContext, SharedStyleContext, StyleContext};
use style::dom::TNode;
use style::selector_impl::ServoSelectorImpl;
use style::traversal::RestyleResult;
Expand Down Expand Up @@ -81,6 +81,10 @@ impl<'lc, N> DomTraversalContext<N> for RecalcStyleAndConstructFlows<'lc>
fn process_postorder(&self, node: N) {
construct_flows_at(&self.context, self.root, node);
}

fn local_context(&self) -> &LocalStyleContext {
self.context.local_context()
}
}

/// A bottom-up, parallelizable traversal.
Expand Down
2 changes: 1 addition & 1 deletion components/script/Cargo.toml
Expand Up @@ -65,7 +65,7 @@ regex = "0.1.43"
rustc-serialize = "0.3"
script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
selectors = {version = "0.8", features = ["heap_size"]}
selectors = {version = "0.9", features = ["heap_size"]}
serde = "0.8"
smallvec = "0.1"
string_cache = {version = "0.2.23", features = ["heap_size", "unstable"]}
Expand Down
5 changes: 5 additions & 0 deletions components/script/layout_wrapper.rs
Expand Up @@ -444,6 +444,11 @@ impl<'le> TElement for ServoLayoutElement<'le> {
}
}

impl<'le> PartialEq for ServoLayoutElement<'le> {
fn eq(&self, other: &Self) -> bool {
self.as_node() == other.as_node()
}
}

impl<'le> ServoLayoutElement<'le> {
fn from_layout_js(el: LayoutJS<Element>) -> ServoLayoutElement<'le> {
Expand Down
2 changes: 1 addition & 1 deletion components/script_layout_interface/Cargo.toml
Expand Up @@ -27,7 +27,7 @@ plugins = {path = "../plugins"}
profile_traits = {path = "../profile_traits"}
range = {path = "../range"}
script_traits = {path = "../script_traits"}
selectors = {version = "0.8", features = ["heap_size"]}
selectors = {version = "0.9", features = ["heap_size"]}
string_cache = {version = "0.2.23", features = ["heap_size"]}
style = {path = "../style"}
url = {version = "1.2", features = ["heap_size"]}
Expand Down
12 changes: 6 additions & 6 deletions components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/style/Cargo.toml
Expand Up @@ -38,7 +38,7 @@ num-traits = "0.1.32"
ordered-float = "0.2.2"
rand = "0.3"
rustc-serialize = "0.3"
selectors = "0.8.2"
selectors = "0.9"
serde = {version = "0.8", optional = true}
serde_macros = {version = "0.8", optional = true}
smallvec = "0.1"
Expand Down
1 change: 1 addition & 0 deletions components/style/context.rs
Expand Up @@ -7,6 +7,7 @@
use animation::Animation;
use app_units::Au;
use dom::OpaqueNode;
use dom::TElement;
use error_reporting::ParseErrorReporter;
use euclid::Size2D;
use matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache};
Expand Down
2 changes: 1 addition & 1 deletion components/style/dom.rs
Expand Up @@ -201,7 +201,7 @@ pub trait PresentationalHintsSynthetizer {
where V: Push<DeclarationBlock<Vec<PropertyDeclaration>>>;
}

pub trait TElement : Sized + Copy + Clone + ElementExt + PresentationalHintsSynthetizer {
pub trait TElement : PartialEq + Sized + Copy + Clone + ElementExt + PresentationalHintsSynthetizer {
type ConcreteNode: TNode<ConcreteElement = Self, ConcreteDocument = Self::ConcreteDocument>;
type ConcreteDocument: TDocument<ConcreteNode = Self::ConcreteNode, ConcreteElement = Self>;

Expand Down

0 comments on commit 3af774b

Please sign in to comment.