mirror of
https://github.com/servo/servo.git
synced 2025-08-13 17:35:36 +01:00
Auto merge of #14642 - bholley:scoped_tls, r=emilio
Use Scoped TLS in the style system and eliminate UnsafeNode usage in the StyleSharingCandidateCache See the discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1323372 @emilio Please review, but don't merge yet until we get the upstream changes into Rayon. CC @SimonSapin @heycam @upsuper @Manishearth @pcwalton @nikomatsakis <!-- 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/14642) <!-- Reviewable:end -->
This commit is contained in:
commit
8fd8d61614
23 changed files with 289 additions and 274 deletions
20
Cargo.lock
generated
20
Cargo.lock
generated
|
@ -1315,7 +1315,7 @@ dependencies = [
|
||||||
"plugins 0.0.1",
|
"plugins 0.0.1",
|
||||||
"profile_traits 0.0.1",
|
"profile_traits 0.0.1",
|
||||||
"range 0.0.1",
|
"range 0.0.1",
|
||||||
"rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rayon 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"script_layout_interface 0.0.1",
|
"script_layout_interface 0.0.1",
|
||||||
"script_traits 0.0.1",
|
"script_traits 0.0.1",
|
||||||
"selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1361,7 +1361,7 @@ dependencies = [
|
||||||
"parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"plugins 0.0.1",
|
"plugins 0.0.1",
|
||||||
"profile_traits 0.0.1",
|
"profile_traits 0.0.1",
|
||||||
"rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rayon 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"script 0.0.1",
|
"script 0.0.1",
|
||||||
"script_layout_interface 0.0.1",
|
"script_layout_interface 0.0.1",
|
||||||
"script_traits 0.0.1",
|
"script_traits 0.0.1",
|
||||||
|
@ -2190,6 +2190,17 @@ dependencies = [
|
||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rayon"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num_cpus 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ref_filter_map"
|
name = "ref_filter_map"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
|
@ -2744,7 +2755,7 @@ dependencies = [
|
||||||
"plugins 0.0.1",
|
"plugins 0.0.1",
|
||||||
"quickersort 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quickersort 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rayon 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 0.1.76 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 0.1.76 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -2771,7 +2782,7 @@ dependencies = [
|
||||||
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"owning_ref 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"owning_ref 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rayon 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"servo_atoms 0.0.1",
|
"servo_atoms 0.0.1",
|
||||||
|
@ -3481,6 +3492,7 @@ dependencies = [
|
||||||
"checksum quote 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1e0c9bc6bfb0a60d539aab6e338207c1a5456e62f5bd5375132cee119aa4b3"
|
"checksum quote 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1e0c9bc6bfb0a60d539aab6e338207c1a5456e62f5bd5375132cee119aa4b3"
|
||||||
"checksum rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2791d88c6defac799c3f20d74f094ca33b9332612d9aef9078519c82e4fe04a5"
|
"checksum rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2791d88c6defac799c3f20d74f094ca33b9332612d9aef9078519c82e4fe04a5"
|
||||||
"checksum rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b6a6e05e0e6b703e9f2ad266eb63f3712e693a17a2702b95a23de14ce8defa9"
|
"checksum rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b6a6e05e0e6b703e9f2ad266eb63f3712e693a17a2702b95a23de14ce8defa9"
|
||||||
|
"checksum rayon 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50c575b58c2b109e2fbc181820cbe177474f35610ff9e357dc75f6bac854ffbf"
|
||||||
"checksum ref_filter_map 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b5ceb840e4009da4841ed22a15eb49f64fdd00a2138945c5beacf506b2fb5ed"
|
"checksum ref_filter_map 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b5ceb840e4009da4841ed22a15eb49f64fdd00a2138945c5beacf506b2fb5ed"
|
||||||
"checksum ref_slice 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "546bb4aa91c85f232732cc5b3c8097ea97ae9a77304f9ab4df8b203ff7672dad"
|
"checksum ref_slice 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "546bb4aa91c85f232732cc5b3c8097ea97ae9a77304f9ab4df8b203ff7672dad"
|
||||||
"checksum regex 0.1.76 (registry+https://github.com/rust-lang/crates.io-index)" = "63b49f873f36ddc838d773972511e5fed2ef7350885af07d58e2f48ce8073dcd"
|
"checksum regex 0.1.76 (registry+https://github.com/rust-lang/crates.io-index)" = "63b49f873f36ddc838d773972511e5fed2ef7350885af07d58e2f48ce8073dcd"
|
||||||
|
|
|
@ -31,7 +31,7 @@ parking_lot = "0.3.3"
|
||||||
plugins = {path = "../plugins"}
|
plugins = {path = "../plugins"}
|
||||||
profile_traits = {path = "../profile_traits"}
|
profile_traits = {path = "../profile_traits"}
|
||||||
range = {path = "../range"}
|
range = {path = "../range"}
|
||||||
rayon = "0.5"
|
rayon = "0.6"
|
||||||
script_layout_interface = {path = "../script_layout_interface"}
|
script_layout_interface = {path = "../script_layout_interface"}
|
||||||
script_traits = {path = "../script_traits"}
|
script_traits = {path = "../script_traits"}
|
||||||
selectors = "0.15"
|
selectors = "0.15"
|
||||||
|
|
|
@ -19,67 +19,72 @@ use net_traits::image_cache_thread::{ImageOrMetadataAvailable, UsePlaceholder};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::borrow::Borrow;
|
|
||||||
use std::cell::{RefCell, RefMut};
|
use std::cell::{RefCell, RefMut};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::hash::BuildHasherDefault;
|
use std::hash::BuildHasherDefault;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use style::context::{SharedStyleContext, ThreadLocalStyleContext};
|
use style::context::{SharedStyleContext, ThreadLocalStyleContext};
|
||||||
|
use style::dom::TElement;
|
||||||
|
|
||||||
pub struct ThreadLocalLayoutContext {
|
/// TLS data scoped to the traversal.
|
||||||
pub style_context: ThreadLocalStyleContext,
|
pub struct ScopedThreadLocalLayoutContext<E: TElement> {
|
||||||
|
pub style_context: ThreadLocalStyleContext<E>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<E: TElement> ScopedThreadLocalLayoutContext<E> {
|
||||||
|
pub fn new(shared: &SharedLayoutContext) -> Self {
|
||||||
|
ScopedThreadLocalLayoutContext {
|
||||||
|
style_context: ThreadLocalStyleContext::new(&shared.style_context),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TLS data that persists across traversals.
|
||||||
|
pub struct PersistentThreadLocalLayoutContext {
|
||||||
|
// FontContext uses Rc all over the place and so isn't Send, which means we
|
||||||
|
// can't use ScopedTLS for it. There's also no reason to scope it to the
|
||||||
|
// traversal, and performance is probably better if we don't.
|
||||||
pub font_context: RefCell<FontContext>,
|
pub font_context: RefCell<FontContext>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThreadLocalLayoutContext {
|
impl PersistentThreadLocalLayoutContext {
|
||||||
pub fn new(shared: &SharedLayoutContext) -> Rc<Self> {
|
pub fn new(shared: &SharedLayoutContext) -> Rc<Self> {
|
||||||
let font_cache_thread = shared.font_cache_thread.lock().unwrap().clone();
|
let font_cache_thread = shared.font_cache_thread.lock().unwrap().clone();
|
||||||
let local_style_data = shared.style_context.local_context_creation_data.lock().unwrap();
|
Rc::new(PersistentThreadLocalLayoutContext {
|
||||||
|
|
||||||
Rc::new(ThreadLocalLayoutContext {
|
|
||||||
style_context: ThreadLocalStyleContext::new(&local_style_data),
|
|
||||||
font_context: RefCell::new(FontContext::new(font_cache_thread)),
|
font_context: RefCell::new(FontContext::new(font_cache_thread)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Borrow<ThreadLocalStyleContext> for ThreadLocalLayoutContext {
|
impl HeapSizeOf for PersistentThreadLocalLayoutContext {
|
||||||
fn borrow(&self) -> &ThreadLocalStyleContext {
|
|
||||||
&self.style_context
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HeapSizeOf for ThreadLocalLayoutContext {
|
|
||||||
// FIXME(njn): measure other fields eventually.
|
|
||||||
fn heap_size_of_children(&self) -> usize {
|
fn heap_size_of_children(&self) -> usize {
|
||||||
self.font_context.heap_size_of_children()
|
self.font_context.heap_size_of_children()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local!(static LOCAL_CONTEXT_KEY: RefCell<Option<Rc<ThreadLocalLayoutContext>>> = RefCell::new(None));
|
thread_local!(static LOCAL_CONTEXT_KEY: RefCell<Option<Rc<PersistentThreadLocalLayoutContext>>> = RefCell::new(None));
|
||||||
|
|
||||||
pub fn heap_size_of_local_context() -> usize {
|
fn create_or_get_persistent_context(shared: &SharedLayoutContext)
|
||||||
LOCAL_CONTEXT_KEY.with(|r| {
|
-> Rc<PersistentThreadLocalLayoutContext> {
|
||||||
r.borrow().clone().map_or(0, |context| context.heap_size_of_children())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keep this implementation in sync with the one in ports/geckolib/traversal.rs.
|
|
||||||
pub fn create_or_get_local_context(shared: &SharedLayoutContext)
|
|
||||||
-> Rc<ThreadLocalLayoutContext> {
|
|
||||||
LOCAL_CONTEXT_KEY.with(|r| {
|
LOCAL_CONTEXT_KEY.with(|r| {
|
||||||
let mut r = r.borrow_mut();
|
let mut r = r.borrow_mut();
|
||||||
if let Some(context) = r.clone() {
|
if let Some(context) = r.clone() {
|
||||||
context
|
context
|
||||||
} else {
|
} else {
|
||||||
let context = ThreadLocalLayoutContext::new(shared);
|
let context = PersistentThreadLocalLayoutContext::new(shared);
|
||||||
*r = Some(context.clone());
|
*r = Some(context.clone());
|
||||||
context
|
context
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn heap_size_of_persistent_local_context() -> usize {
|
||||||
|
LOCAL_CONTEXT_KEY.with(|r| {
|
||||||
|
r.borrow().clone().map_or(0, |context| context.heap_size_of_children())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Layout information shared among all workers. This must be thread-safe.
|
/// Layout information shared among all workers. This must be thread-safe.
|
||||||
pub struct SharedLayoutContext {
|
pub struct SharedLayoutContext {
|
||||||
/// Bits shared by the layout and style system.
|
/// Bits shared by the layout and style system.
|
||||||
|
@ -100,24 +105,17 @@ pub struct SharedLayoutContext {
|
||||||
BuildHasherDefault<FnvHasher>>>>,
|
BuildHasherDefault<FnvHasher>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Borrow<SharedStyleContext> for SharedLayoutContext {
|
|
||||||
fn borrow(&self) -> &SharedStyleContext {
|
|
||||||
&self.style_context
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct LayoutContext<'a> {
|
pub struct LayoutContext<'a> {
|
||||||
pub shared: &'a SharedLayoutContext,
|
pub shared: &'a SharedLayoutContext,
|
||||||
pub thread_local: &'a ThreadLocalLayoutContext,
|
pub persistent: Rc<PersistentThreadLocalLayoutContext>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> LayoutContext<'a> {
|
impl<'a> LayoutContext<'a> {
|
||||||
pub fn new(shared: &'a SharedLayoutContext,
|
pub fn new(shared: &'a SharedLayoutContext) -> Self
|
||||||
thread_local: &'a ThreadLocalLayoutContext) -> Self
|
|
||||||
{
|
{
|
||||||
LayoutContext {
|
LayoutContext {
|
||||||
shared: shared,
|
shared: shared,
|
||||||
thread_local: thread_local,
|
persistent: create_or_get_persistent_context(shared),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +136,7 @@ impl<'a> LayoutContext<'a> {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn font_context(&self) -> RefMut<FontContext> {
|
pub fn font_context(&self) -> RefMut<FontContext> {
|
||||||
self.thread_local.font_context.borrow_mut()
|
self.persistent.font_context.borrow_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
|
|
||||||
#![allow(unsafe_code)]
|
#![allow(unsafe_code)]
|
||||||
|
|
||||||
use context::{LayoutContext, SharedLayoutContext, ThreadLocalLayoutContext};
|
use context::{LayoutContext, SharedLayoutContext};
|
||||||
use context::create_or_get_local_context;
|
|
||||||
use flow::{self, Flow, MutableFlowUtils, PostorderFlowTraversal, PreorderFlowTraversal};
|
use flow::{self, Flow, MutableFlowUtils, PostorderFlowTraversal, PreorderFlowTraversal};
|
||||||
use flow_ref::FlowRef;
|
use flow_ref::FlowRef;
|
||||||
use profile_traits::time::{self, TimerMetadata, profile};
|
use profile_traits::time::{self, TimerMetadata, profile};
|
||||||
|
@ -51,7 +50,7 @@ pub fn borrowed_flow_to_unsafe_flow(flow: &Flow) -> UnsafeFlow {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type ChunkedFlowTraversalFunction<'scope> =
|
pub type ChunkedFlowTraversalFunction<'scope> =
|
||||||
extern "Rust" fn(Box<[UnsafeFlow]>, &'scope SharedLayoutContext, &rayon::Scope<'scope>);
|
extern "Rust" fn(Box<[UnsafeFlow]>, &rayon::Scope<'scope>, &'scope SharedLayoutContext);
|
||||||
|
|
||||||
pub type FlowTraversalFunction = extern "Rust" fn(UnsafeFlow, &LayoutContext);
|
pub type FlowTraversalFunction = extern "Rust" fn(UnsafeFlow, &LayoutContext);
|
||||||
|
|
||||||
|
@ -133,23 +132,22 @@ trait ParallelPostorderFlowTraversal : PostorderFlowTraversal {
|
||||||
trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
|
trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
|
||||||
fn run_parallel<'scope>(&self,
|
fn run_parallel<'scope>(&self,
|
||||||
unsafe_flows: &[UnsafeFlow],
|
unsafe_flows: &[UnsafeFlow],
|
||||||
layout_context: &'scope SharedLayoutContext,
|
scope: &rayon::Scope<'scope>,
|
||||||
scope: &rayon::Scope<'scope>);
|
shared: &'scope SharedLayoutContext);
|
||||||
|
|
||||||
fn should_record_thread_ids(&self) -> bool;
|
fn should_record_thread_ids(&self) -> bool;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn run_parallel_helper<'scope>(&self,
|
fn run_parallel_helper<'scope>(&self,
|
||||||
unsafe_flows: &[UnsafeFlow],
|
unsafe_flows: &[UnsafeFlow],
|
||||||
shared: &'scope SharedLayoutContext,
|
|
||||||
scope: &rayon::Scope<'scope>,
|
scope: &rayon::Scope<'scope>,
|
||||||
|
shared: &'scope SharedLayoutContext,
|
||||||
top_down_func: ChunkedFlowTraversalFunction<'scope>,
|
top_down_func: ChunkedFlowTraversalFunction<'scope>,
|
||||||
bottom_up_func: FlowTraversalFunction)
|
bottom_up_func: FlowTraversalFunction)
|
||||||
{
|
{
|
||||||
let tlc = create_or_get_local_context(shared);
|
|
||||||
let context = LayoutContext::new(&shared, &*tlc);
|
|
||||||
|
|
||||||
let mut discovered_child_flows = vec![];
|
let mut discovered_child_flows = vec![];
|
||||||
|
let context = LayoutContext::new(&shared);
|
||||||
|
|
||||||
for unsafe_flow in unsafe_flows {
|
for unsafe_flow in unsafe_flows {
|
||||||
let mut had_children = false;
|
let mut had_children = false;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -187,7 +185,7 @@ trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
|
||||||
let nodes = chunk.iter().cloned().collect::<Vec<_>>().into_boxed_slice();
|
let nodes = chunk.iter().cloned().collect::<Vec<_>>().into_boxed_slice();
|
||||||
|
|
||||||
scope.spawn(move |scope| {
|
scope.spawn(move |scope| {
|
||||||
top_down_func(nodes, shared, scope);
|
top_down_func(nodes, scope, shared);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,12 +194,12 @@ trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
|
||||||
impl<'a> ParallelPreorderFlowTraversal for AssignISizes<'a> {
|
impl<'a> ParallelPreorderFlowTraversal for AssignISizes<'a> {
|
||||||
fn run_parallel<'scope>(&self,
|
fn run_parallel<'scope>(&self,
|
||||||
unsafe_flows: &[UnsafeFlow],
|
unsafe_flows: &[UnsafeFlow],
|
||||||
layout_context: &'scope SharedLayoutContext,
|
scope: &rayon::Scope<'scope>,
|
||||||
scope: &rayon::Scope<'scope>)
|
shared: &'scope SharedLayoutContext)
|
||||||
{
|
{
|
||||||
self.run_parallel_helper(unsafe_flows,
|
self.run_parallel_helper(unsafe_flows,
|
||||||
layout_context,
|
|
||||||
scope,
|
scope,
|
||||||
|
shared,
|
||||||
assign_inline_sizes,
|
assign_inline_sizes,
|
||||||
assign_block_sizes_and_store_overflow)
|
assign_block_sizes_and_store_overflow)
|
||||||
}
|
}
|
||||||
|
@ -214,12 +212,12 @@ impl<'a> ParallelPreorderFlowTraversal for AssignISizes<'a> {
|
||||||
impl<'a> ParallelPostorderFlowTraversal for AssignBSizes<'a> {}
|
impl<'a> ParallelPostorderFlowTraversal for AssignBSizes<'a> {}
|
||||||
|
|
||||||
fn assign_inline_sizes<'scope>(unsafe_flows: Box<[UnsafeFlow]>,
|
fn assign_inline_sizes<'scope>(unsafe_flows: Box<[UnsafeFlow]>,
|
||||||
shared_layout_context: &'scope SharedLayoutContext,
|
scope: &rayon::Scope<'scope>,
|
||||||
scope: &rayon::Scope<'scope>) {
|
shared: &'scope SharedLayoutContext) {
|
||||||
let assign_inline_sizes_traversal = AssignISizes {
|
let assign_inline_sizes_traversal = AssignISizes {
|
||||||
shared_context: &shared_layout_context.style_context,
|
shared_context: &shared.style_context,
|
||||||
};
|
};
|
||||||
assign_inline_sizes_traversal.run_parallel(&unsafe_flows, shared_layout_context, scope)
|
assign_inline_sizes_traversal.run_parallel(&unsafe_flows, scope, shared)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assign_block_sizes_and_store_overflow(
|
fn assign_block_sizes_and_store_overflow(
|
||||||
|
@ -238,8 +236,7 @@ pub fn traverse_flow_tree_preorder(
|
||||||
shared: &SharedLayoutContext,
|
shared: &SharedLayoutContext,
|
||||||
queue: &rayon::ThreadPool) {
|
queue: &rayon::ThreadPool) {
|
||||||
if opts::get().bubble_inline_sizes_separately {
|
if opts::get().bubble_inline_sizes_separately {
|
||||||
let tlc = ThreadLocalLayoutContext::new(shared);
|
let context = LayoutContext::new(shared);
|
||||||
let context = LayoutContext::new(shared, &*tlc);
|
|
||||||
let bubble_inline_sizes = BubbleISizes { layout_context: &context };
|
let bubble_inline_sizes = BubbleISizes { layout_context: &context };
|
||||||
root.traverse_postorder(&bubble_inline_sizes);
|
root.traverse_postorder(&bubble_inline_sizes);
|
||||||
}
|
}
|
||||||
|
@ -250,7 +247,7 @@ pub fn traverse_flow_tree_preorder(
|
||||||
rayon::scope(move |scope| {
|
rayon::scope(move |scope| {
|
||||||
profile(time::ProfilerCategory::LayoutParallelWarmup,
|
profile(time::ProfilerCategory::LayoutParallelWarmup,
|
||||||
profiler_metadata, time_profiler_chan, move || {
|
profiler_metadata, time_profiler_chan, move || {
|
||||||
assign_inline_sizes(nodes, &shared, scope);
|
assign_inline_sizes(nodes, scope, &shared);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use construct::ConstructionResult;
|
use construct::ConstructionResult;
|
||||||
use context::SharedLayoutContext;
|
use context::{ScopedThreadLocalLayoutContext, SharedLayoutContext};
|
||||||
use context::create_or_get_local_context;
|
|
||||||
use euclid::point::Point2D;
|
use euclid::point::Point2D;
|
||||||
use euclid::rect::Rect;
|
use euclid::rect::Rect;
|
||||||
use euclid::size::Size2D;
|
use euclid::size::Size2D;
|
||||||
|
@ -646,10 +645,10 @@ pub fn process_resolved_style_request<'a, N>(shared: &SharedLayoutContext,
|
||||||
// we'd need a mechanism to prevent detect when it's stale (since we don't
|
// we'd need a mechanism to prevent detect when it's stale (since we don't
|
||||||
// traverse display:none subtrees during restyle).
|
// traverse display:none subtrees during restyle).
|
||||||
let display_none_root = if element.get_data().is_none() {
|
let display_none_root = if element.get_data().is_none() {
|
||||||
let tlc = create_or_get_local_context(shared);
|
let mut tlc = ScopedThreadLocalLayoutContext::new(shared);
|
||||||
let context = StyleContext {
|
let context = StyleContext {
|
||||||
shared: &shared.style_context,
|
shared: &shared.style_context,
|
||||||
thread_local: &tlc.style_context,
|
thread_local: &mut tlc.style_context,
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(style_element_in_display_none_subtree(&context, element,
|
Some(style_element_in_display_none_subtree(&context, element,
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
//! Implements sequential traversals over the DOM and flow trees.
|
//! Implements sequential traversals over the DOM and flow trees.
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use context::{LayoutContext, SharedLayoutContext, ThreadLocalLayoutContext};
|
use context::{LayoutContext, SharedLayoutContext};
|
||||||
use display_list_builder::DisplayListBuildState;
|
use display_list_builder::DisplayListBuildState;
|
||||||
use euclid::point::Point2D;
|
use euclid::point::Point2D;
|
||||||
use floats::SpeculatedFloatPlacement;
|
use floats::SpeculatedFloatPlacement;
|
||||||
|
@ -34,8 +34,7 @@ pub fn resolve_generated_content(root: &mut Flow, shared: &SharedLayoutContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let tlc = ThreadLocalLayoutContext::new(shared);
|
let layout_context = LayoutContext::new(shared);
|
||||||
let layout_context = LayoutContext::new(shared, &*tlc);
|
|
||||||
let mut traversal = ResolveGeneratedContent::new(&layout_context);
|
let mut traversal = ResolveGeneratedContent::new(&layout_context);
|
||||||
doit(root, 0, &mut traversal)
|
doit(root, 0, &mut traversal)
|
||||||
}
|
}
|
||||||
|
@ -58,8 +57,7 @@ pub fn traverse_flow_tree_preorder(root: &mut Flow,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let tlc = ThreadLocalLayoutContext::new(shared);
|
let layout_context = LayoutContext::new(shared);
|
||||||
let layout_context = LayoutContext::new(shared, &*tlc);
|
|
||||||
|
|
||||||
if opts::get().bubble_inline_sizes_separately {
|
if opts::get().bubble_inline_sizes_separately {
|
||||||
let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context };
|
let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context };
|
||||||
|
|
|
@ -5,15 +5,13 @@
|
||||||
//! Traversals over the DOM and flow trees, running the layout computations.
|
//! Traversals over the DOM and flow trees, running the layout computations.
|
||||||
|
|
||||||
use construct::FlowConstructor;
|
use construct::FlowConstructor;
|
||||||
use context::{LayoutContext, SharedLayoutContext, ThreadLocalLayoutContext};
|
use context::{LayoutContext, ScopedThreadLocalLayoutContext, SharedLayoutContext};
|
||||||
use context::create_or_get_local_context;
|
|
||||||
use display_list_builder::DisplayListBuildState;
|
use display_list_builder::DisplayListBuildState;
|
||||||
use flow::{self, PreorderFlowTraversal};
|
use flow::{self, PreorderFlowTraversal};
|
||||||
use flow::{CAN_BE_FRAGMENTED, Flow, ImmutableFlowUtils, PostorderFlowTraversal};
|
use flow::{CAN_BE_FRAGMENTED, Flow, ImmutableFlowUtils, PostorderFlowTraversal};
|
||||||
use gfx::display_list::OpaqueNode;
|
use gfx::display_list::OpaqueNode;
|
||||||
use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode};
|
use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode};
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
use std::rc::Rc;
|
|
||||||
use style::atomic_refcell::AtomicRefCell;
|
use style::atomic_refcell::AtomicRefCell;
|
||||||
use style::context::{SharedStyleContext, StyleContext};
|
use style::context::{SharedStyleContext, StyleContext};
|
||||||
use style::data::ElementData;
|
use style::data::ElementData;
|
||||||
|
@ -56,9 +54,10 @@ impl<N> DomTraversal<N> for RecalcStyleAndConstructFlows
|
||||||
where N: LayoutNode + TNode,
|
where N: LayoutNode + TNode,
|
||||||
N::ConcreteElement: TElement
|
N::ConcreteElement: TElement
|
||||||
{
|
{
|
||||||
type ThreadLocalContext = ThreadLocalLayoutContext;
|
type ThreadLocalContext = ScopedThreadLocalLayoutContext<N::ConcreteElement>;
|
||||||
|
|
||||||
fn process_preorder(&self, node: N, traversal_data: &mut PerLevelTraversalData) {
|
fn process_preorder(&self, traversal_data: &mut PerLevelTraversalData,
|
||||||
|
thread_local: &mut Self::ThreadLocalContext, node: N) {
|
||||||
// FIXME(pcwalton): Stop allocating here. Ideally this should just be
|
// FIXME(pcwalton): Stop allocating here. Ideally this should just be
|
||||||
// done by the HTML parser.
|
// done by the HTML parser.
|
||||||
node.initialize_data();
|
node.initialize_data();
|
||||||
|
@ -66,19 +65,17 @@ impl<N> DomTraversal<N> for RecalcStyleAndConstructFlows
|
||||||
if !node.is_text_node() {
|
if !node.is_text_node() {
|
||||||
let el = node.as_element().unwrap();
|
let el = node.as_element().unwrap();
|
||||||
let mut data = el.mutate_data().unwrap();
|
let mut data = el.mutate_data().unwrap();
|
||||||
let tlc = create_or_get_local_context(&self.shared);
|
let mut context = StyleContext {
|
||||||
let context = StyleContext {
|
|
||||||
shared: &self.shared.style_context,
|
shared: &self.shared.style_context,
|
||||||
thread_local: &tlc.style_context,
|
thread_local: &mut thread_local.style_context,
|
||||||
};
|
};
|
||||||
recalc_style_at(self, traversal_data, &context, el, &mut data);
|
recalc_style_at(self, traversal_data, &mut context, el, &mut data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_postorder(&self, node: N) {
|
fn process_postorder(&self, thread_local: &mut Self::ThreadLocalContext, node: N) {
|
||||||
let tlc = create_or_get_local_context(&self.shared);
|
let context = LayoutContext::new(&self.shared);
|
||||||
let context = LayoutContext::new(&self.shared, &*tlc);
|
construct_flows_at(&context, thread_local, self.root, node);
|
||||||
construct_flows_at(&context, self.root, node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn text_node_needs_traversal(node: N) -> bool {
|
fn text_node_needs_traversal(node: N) -> bool {
|
||||||
|
@ -103,8 +100,8 @@ impl<N> DomTraversal<N> for RecalcStyleAndConstructFlows
|
||||||
&self.shared.style_context
|
&self.shared.style_context
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_or_get_thread_local_context(&self) -> Rc<ThreadLocalLayoutContext> {
|
fn create_thread_local_context(&self) -> Self::ThreadLocalContext {
|
||||||
create_or_get_local_context(&self.shared)
|
ScopedThreadLocalLayoutContext::new(&self.shared)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +114,9 @@ pub trait PostorderNodeMutTraversal<ConcreteThreadSafeLayoutNode: ThreadSafeLayo
|
||||||
/// The flow construction traversal, which builds flows for styled nodes.
|
/// The flow construction traversal, which builds flows for styled nodes.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn construct_flows_at<'a, N>(context: &LayoutContext<'a>, root: OpaqueNode, node: N)
|
fn construct_flows_at<'a, N>(context: &LayoutContext<'a>,
|
||||||
|
_thread_local: &ScopedThreadLocalLayoutContext<N::ConcreteElement>,
|
||||||
|
root: OpaqueNode, node: N)
|
||||||
where N: LayoutNode,
|
where N: LayoutNode,
|
||||||
{
|
{
|
||||||
debug!("construct_flows_at: {:?}", node);
|
debug!("construct_flows_at: {:?}", node);
|
||||||
|
|
|
@ -27,7 +27,7 @@ net_traits = {path = "../net_traits"}
|
||||||
parking_lot = {version = "0.3.3", features = ["nightly"]}
|
parking_lot = {version = "0.3.3", features = ["nightly"]}
|
||||||
plugins = {path = "../plugins"}
|
plugins = {path = "../plugins"}
|
||||||
profile_traits = {path = "../profile_traits"}
|
profile_traits = {path = "../profile_traits"}
|
||||||
rayon = "0.5"
|
rayon = "0.6"
|
||||||
script = {path = "../script"}
|
script = {path = "../script"}
|
||||||
script_layout_interface = {path = "../script_layout_interface"}
|
script_layout_interface = {path = "../script_layout_interface"}
|
||||||
script_traits = {path = "../script_traits"}
|
script_traits = {path = "../script_traits"}
|
||||||
|
|
|
@ -63,7 +63,8 @@ use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||||
use ipc_channel::router::ROUTER;
|
use ipc_channel::router::ROUTER;
|
||||||
use layout::animation;
|
use layout::animation;
|
||||||
use layout::construct::ConstructionResult;
|
use layout::construct::ConstructionResult;
|
||||||
use layout::context::{LayoutContext, SharedLayoutContext, ThreadLocalLayoutContext, heap_size_of_local_context};
|
use layout::context::{LayoutContext, SharedLayoutContext};
|
||||||
|
use layout::context::heap_size_of_persistent_local_context;
|
||||||
use layout::display_list_builder::ToGfxColor;
|
use layout::display_list_builder::ToGfxColor;
|
||||||
use layout::flow::{self, Flow, ImmutableFlowUtils, MutableFlowUtils, MutableOwnedFlowUtils};
|
use layout::flow::{self, Flow, ImmutableFlowUtils, MutableFlowUtils, MutableOwnedFlowUtils};
|
||||||
use layout::flow_ref::FlowRef;
|
use layout::flow_ref::FlowRef;
|
||||||
|
@ -723,11 +724,11 @@ impl LayoutThread {
|
||||||
size: stylist.heap_size_of_children(),
|
size: stylist.heap_size_of_children(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// The LayoutThread has a context in TLS...
|
// The LayoutThread has data in Persistent TLS...
|
||||||
reports.push(Report {
|
reports.push(Report {
|
||||||
path: path![formatted_url, "layout-thread", "local-context"],
|
path: path![formatted_url, "layout-thread", "local-context"],
|
||||||
kind: ReportKind::ExplicitJemallocHeapSize,
|
kind: ReportKind::ExplicitJemallocHeapSize,
|
||||||
size: heap_size_of_local_context(),
|
size: heap_size_of_persistent_local_context(),
|
||||||
});
|
});
|
||||||
|
|
||||||
reports_chan.send(reports);
|
reports_chan.send(reports);
|
||||||
|
@ -1447,8 +1448,7 @@ impl LayoutThread {
|
||||||
self.profiler_metadata(),
|
self.profiler_metadata(),
|
||||||
self.time_profiler_chan.clone(),
|
self.time_profiler_chan.clone(),
|
||||||
|| {
|
|| {
|
||||||
let tlc = ThreadLocalLayoutContext::new(&shared);
|
let context = LayoutContext::new(&shared);
|
||||||
let context = LayoutContext::new(&shared, &*tlc);
|
|
||||||
sequential::store_overflow(&context,
|
sequential::store_overflow(&context,
|
||||||
FlowRef::deref_mut(&mut root_flow) as &mut Flow);
|
FlowRef::deref_mut(&mut root_flow) as &mut Flow);
|
||||||
});
|
});
|
||||||
|
|
|
@ -44,7 +44,7 @@ parking_lot = "0.3.3"
|
||||||
phf = "0.7.20"
|
phf = "0.7.20"
|
||||||
quickersort = "2.0.0"
|
quickersort = "2.0.0"
|
||||||
rand = "0.3"
|
rand = "0.3"
|
||||||
rayon = "0.5"
|
rayon = "0.6"
|
||||||
rustc-serialize = "0.3"
|
rustc-serialize = "0.3"
|
||||||
selectors = "0.15"
|
selectors = "0.15"
|
||||||
serde = {version = "0.8", optional = true}
|
serde = {version = "0.8", optional = true}
|
||||||
|
|
|
@ -6,12 +6,11 @@
|
||||||
|
|
||||||
use animation::Animation;
|
use animation::Animation;
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use dom::OpaqueNode;
|
use dom::{OpaqueNode, TElement};
|
||||||
use error_reporting::ParseErrorReporter;
|
use error_reporting::ParseErrorReporter;
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
use matching::StyleSharingCandidateCache;
|
use matching::StyleSharingCandidateCache;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
@ -76,25 +75,25 @@ pub struct SharedStyleContext {
|
||||||
pub quirks_mode: QuirksMode,
|
pub quirks_mode: QuirksMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ThreadLocalStyleContext {
|
pub struct ThreadLocalStyleContext<E: TElement> {
|
||||||
pub style_sharing_candidate_cache: RefCell<StyleSharingCandidateCache>,
|
pub style_sharing_candidate_cache: StyleSharingCandidateCache<E>,
|
||||||
/// A channel on which new animations that have been triggered by style
|
/// A channel on which new animations that have been triggered by style
|
||||||
/// recalculation can be sent.
|
/// recalculation can be sent.
|
||||||
pub new_animations_sender: Sender<Animation>,
|
pub new_animations_sender: Sender<Animation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThreadLocalStyleContext {
|
impl<E: TElement> ThreadLocalStyleContext<E> {
|
||||||
pub fn new(local_context_creation_data: &ThreadLocalStyleContextCreationInfo) -> Self {
|
pub fn new(shared: &SharedStyleContext) -> Self {
|
||||||
ThreadLocalStyleContext {
|
ThreadLocalStyleContext {
|
||||||
style_sharing_candidate_cache: RefCell::new(StyleSharingCandidateCache::new()),
|
style_sharing_candidate_cache: StyleSharingCandidateCache::new(),
|
||||||
new_animations_sender: local_context_creation_data.new_animations_sender.clone(),
|
new_animations_sender: shared.local_context_creation_data.lock().unwrap().new_animations_sender.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StyleContext<'a> {
|
pub struct StyleContext<'a, E: TElement + 'a> {
|
||||||
pub shared: &'a SharedStyleContext,
|
pub shared: &'a SharedStyleContext,
|
||||||
pub thread_local: &'a ThreadLocalStyleContext,
|
pub thread_local: &'a mut ThreadLocalStyleContext<E>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Why we're doing reflow.
|
/// Why we're doing reflow.
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
use context::{SharedStyleContext, ThreadLocalStyleContext};
|
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
thread_local!(static LOCAL_CONTEXT_KEY: RefCell<Option<Rc<ThreadLocalStyleContext>>> = RefCell::new(None));
|
|
||||||
|
|
||||||
// Keep this implementation in sync with the one in components/layout/context.rs.
|
|
||||||
pub fn create_or_get_local_context(shared: &SharedStyleContext) -> Rc<ThreadLocalStyleContext> {
|
|
||||||
LOCAL_CONTEXT_KEY.with(|r| {
|
|
||||||
let mut r = r.borrow_mut();
|
|
||||||
if let Some(context) = r.clone() {
|
|
||||||
context
|
|
||||||
} else {
|
|
||||||
let context = Rc::new(ThreadLocalStyleContext::new(&shared.local_context_creation_data.lock().unwrap()));
|
|
||||||
*r = Some(context.clone());
|
|
||||||
context
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clear_local_context() {
|
|
||||||
LOCAL_CONTEXT_KEY.with(|r| *r.borrow_mut() = None);
|
|
||||||
}
|
|
|
@ -3,7 +3,6 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
|
||||||
pub mod context;
|
|
||||||
pub mod data;
|
pub mod data;
|
||||||
pub mod restyle_damage;
|
pub mod restyle_damage;
|
||||||
pub mod snapshot;
|
pub mod snapshot;
|
||||||
|
|
|
@ -6,9 +6,8 @@ use atomic_refcell::AtomicRefCell;
|
||||||
use context::{SharedStyleContext, StyleContext, ThreadLocalStyleContext};
|
use context::{SharedStyleContext, StyleContext, ThreadLocalStyleContext};
|
||||||
use data::ElementData;
|
use data::ElementData;
|
||||||
use dom::{NodeInfo, TNode};
|
use dom::{NodeInfo, TNode};
|
||||||
use gecko::context::create_or_get_local_context;
|
|
||||||
use gecko::wrapper::{GeckoElement, GeckoNode};
|
use gecko::wrapper::{GeckoElement, GeckoNode};
|
||||||
use std::rc::Rc; use traversal::{DomTraversal, PerLevelTraversalData, recalc_style_at};
|
use traversal::{DomTraversal, PerLevelTraversalData, recalc_style_at};
|
||||||
|
|
||||||
pub struct RecalcStyleOnly {
|
pub struct RecalcStyleOnly {
|
||||||
shared: SharedStyleContext,
|
shared: SharedStyleContext,
|
||||||
|
@ -23,22 +22,24 @@ impl RecalcStyleOnly {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ln> DomTraversal<GeckoNode<'ln>> for RecalcStyleOnly {
|
impl<'ln> DomTraversal<GeckoNode<'ln>> for RecalcStyleOnly {
|
||||||
type ThreadLocalContext = ThreadLocalStyleContext;
|
type ThreadLocalContext = ThreadLocalStyleContext<GeckoElement<'ln>>;
|
||||||
|
|
||||||
fn process_preorder(&self, node: GeckoNode<'ln>, traversal_data: &mut PerLevelTraversalData) {
|
fn process_preorder(&self, traversal_data: &mut PerLevelTraversalData,
|
||||||
|
thread_local: &mut Self::ThreadLocalContext,
|
||||||
|
node: GeckoNode<'ln>)
|
||||||
|
{
|
||||||
if node.is_element() {
|
if node.is_element() {
|
||||||
let el = node.as_element().unwrap();
|
let el = node.as_element().unwrap();
|
||||||
let mut data = unsafe { el.ensure_data() }.borrow_mut();
|
let mut data = unsafe { el.ensure_data() }.borrow_mut();
|
||||||
let tlc = self.create_or_get_thread_local_context();
|
let mut context = StyleContext {
|
||||||
let context = StyleContext {
|
|
||||||
shared: &self.shared,
|
shared: &self.shared,
|
||||||
thread_local: &*tlc,
|
thread_local: thread_local,
|
||||||
};
|
};
|
||||||
recalc_style_at(self, traversal_data, &context, el, &mut data);
|
recalc_style_at(self, traversal_data, &mut context, el, &mut data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_postorder(&self, _: GeckoNode<'ln>) {
|
fn process_postorder(&self, _: &mut Self::ThreadLocalContext, _: GeckoNode<'ln>) {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ impl<'ln> DomTraversal<GeckoNode<'ln>> for RecalcStyleOnly {
|
||||||
&self.shared
|
&self.shared
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_or_get_thread_local_context(&self) -> Rc<ThreadLocalStyleContext> {
|
fn create_thread_local_context(&self) -> Self::ThreadLocalContext {
|
||||||
create_or_get_local_context(&self.shared)
|
ThreadLocalStyleContext::new(&self.shared)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,7 @@ pub mod parallel;
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
pub mod restyle_hints;
|
pub mod restyle_hints;
|
||||||
pub mod rule_tree;
|
pub mod rule_tree;
|
||||||
|
pub mod scoped_tls;
|
||||||
pub mod selector_parser;
|
pub mod selector_parser;
|
||||||
pub mod stylist;
|
pub mod stylist;
|
||||||
#[cfg(feature = "servo")] #[allow(unsafe_code)] pub mod servo;
|
#[cfg(feature = "servo")] #[allow(unsafe_code)] pub mod servo;
|
||||||
|
|
|
@ -13,7 +13,7 @@ use cache::LRUCache;
|
||||||
use cascade_info::CascadeInfo;
|
use cascade_info::CascadeInfo;
|
||||||
use context::{SharedStyleContext, StyleContext};
|
use context::{SharedStyleContext, StyleContext};
|
||||||
use data::{ComputedStyle, ElementData, ElementStyles, PseudoStyles};
|
use data::{ComputedStyle, ElementData, ElementStyles, PseudoStyles};
|
||||||
use dom::{TElement, TNode, UnsafeNode};
|
use dom::{TElement, TNode};
|
||||||
use properties::{CascadeFlags, ComputedValues, SHAREABLE, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP, cascade};
|
use properties::{CascadeFlags, ComputedValues, SHAREABLE, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP, cascade};
|
||||||
use properties::longhands::display::computed_value as display;
|
use properties::longhands::display::computed_value as display;
|
||||||
use rule_tree::StrongRuleNode;
|
use rule_tree::StrongRuleNode;
|
||||||
|
@ -65,22 +65,29 @@ impl MatchResults {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TElement isn't Send because we want to be careful and explicit about our
|
||||||
|
// parallel traversal, but we need the candidates to be Send so that we can stick
|
||||||
|
// them in ScopedTLS.
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
struct SendElement<E: TElement>(pub E);
|
||||||
|
unsafe impl<E: TElement> Send for SendElement<E> {}
|
||||||
|
|
||||||
/// Information regarding a candidate.
|
/// Information regarding a candidate.
|
||||||
///
|
///
|
||||||
/// TODO: We can stick a lot more info here.
|
/// TODO: We can stick a lot more info here.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct StyleSharingCandidate {
|
struct StyleSharingCandidate<E: TElement> {
|
||||||
/// The node, guaranteed to be an element.
|
/// The element.
|
||||||
node: UnsafeNode,
|
element: SendElement<E>,
|
||||||
/// The cached common style affecting attribute info.
|
/// The cached common style affecting attribute info.
|
||||||
common_style_affecting_attributes: Option<CommonStyleAffectingAttributes>,
|
common_style_affecting_attributes: Option<CommonStyleAffectingAttributes>,
|
||||||
/// the cached class names.
|
/// the cached class names.
|
||||||
class_attributes: Option<Vec<Atom>>,
|
class_attributes: Option<Vec<Atom>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<StyleSharingCandidate> for StyleSharingCandidate {
|
impl<E: TElement> PartialEq<StyleSharingCandidate<E>> for StyleSharingCandidate<E> {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.node == other.node &&
|
self.element == other.element &&
|
||||||
self.common_style_affecting_attributes == other.common_style_affecting_attributes
|
self.common_style_affecting_attributes == other.common_style_affecting_attributes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,13 +97,8 @@ impl PartialEq<StyleSharingCandidate> for StyleSharingCandidate {
|
||||||
///
|
///
|
||||||
/// Note that this cache is flushed every time we steal work from the queue, so
|
/// Note that this cache is flushed every time we steal work from the queue, so
|
||||||
/// storing nodes here temporarily is safe.
|
/// storing nodes here temporarily is safe.
|
||||||
///
|
pub struct StyleSharingCandidateCache<E: TElement> {
|
||||||
/// NB: We store UnsafeNode's, but this is not unsafe. It's a shame being
|
cache: LRUCache<StyleSharingCandidate<E>, ()>,
|
||||||
/// generic over elements is unfeasible (you can make compile style without much
|
|
||||||
/// difficulty, but good luck with layout and all the types with assoc.
|
|
||||||
/// lifetimes).
|
|
||||||
pub struct StyleSharingCandidateCache {
|
|
||||||
cache: LRUCache<StyleSharingCandidate, ()>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -117,7 +119,7 @@ pub enum CacheMiss {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn element_matches_candidate<E: TElement>(element: &E,
|
fn element_matches_candidate<E: TElement>(element: &E,
|
||||||
candidate: &mut StyleSharingCandidate,
|
candidate: &mut StyleSharingCandidate<E>,
|
||||||
candidate_element: &E,
|
candidate_element: &E,
|
||||||
shared_context: &SharedStyleContext)
|
shared_context: &SharedStyleContext)
|
||||||
-> Result<ComputedStyle, CacheMiss> {
|
-> Result<ComputedStyle, CacheMiss> {
|
||||||
|
@ -193,7 +195,7 @@ fn element_matches_candidate<E: TElement>(element: &E,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn have_same_common_style_affecting_attributes<E: TElement>(element: &E,
|
fn have_same_common_style_affecting_attributes<E: TElement>(element: &E,
|
||||||
candidate: &mut StyleSharingCandidate,
|
candidate: &mut StyleSharingCandidate<E>,
|
||||||
candidate_element: &E) -> bool {
|
candidate_element: &E) -> bool {
|
||||||
if candidate.common_style_affecting_attributes.is_none() {
|
if candidate.common_style_affecting_attributes.is_none() {
|
||||||
candidate.common_style_affecting_attributes =
|
candidate.common_style_affecting_attributes =
|
||||||
|
@ -272,7 +274,7 @@ pub fn rare_style_affecting_attributes() -> [LocalName; 3] {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn have_same_class<E: TElement>(element: &E,
|
fn have_same_class<E: TElement>(element: &E,
|
||||||
candidate: &mut StyleSharingCandidate,
|
candidate: &mut StyleSharingCandidate<E>,
|
||||||
candidate_element: &E) -> bool {
|
candidate_element: &E) -> bool {
|
||||||
// XXX Efficiency here, I'm only validating ideas.
|
// XXX Efficiency here, I'm only validating ideas.
|
||||||
let mut element_class_attributes = vec![];
|
let mut element_class_attributes = vec![];
|
||||||
|
@ -304,18 +306,18 @@ fn match_same_sibling_affecting_rules<E: TElement>(element: &E,
|
||||||
|
|
||||||
static STYLE_SHARING_CANDIDATE_CACHE_SIZE: usize = 8;
|
static STYLE_SHARING_CANDIDATE_CACHE_SIZE: usize = 8;
|
||||||
|
|
||||||
impl StyleSharingCandidateCache {
|
impl<E: TElement> StyleSharingCandidateCache<E> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
StyleSharingCandidateCache {
|
StyleSharingCandidateCache {
|
||||||
cache: LRUCache::new(STYLE_SHARING_CANDIDATE_CACHE_SIZE),
|
cache: LRUCache::new(STYLE_SHARING_CANDIDATE_CACHE_SIZE),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn iter_mut(&mut self) -> IterMut<(StyleSharingCandidate, ())> {
|
fn iter_mut(&mut self) -> IterMut<(StyleSharingCandidate<E>, ())> {
|
||||||
self.cache.iter_mut()
|
self.cache.iter_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_if_possible<E: TElement>(&mut self,
|
pub fn insert_if_possible(&mut self,
|
||||||
element: &E,
|
element: &E,
|
||||||
style: &Arc<ComputedValues>,
|
style: &Arc<ComputedValues>,
|
||||||
relations: StyleRelations) {
|
relations: StyleRelations) {
|
||||||
|
@ -348,10 +350,10 @@ impl StyleSharingCandidateCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Inserting into cache: {:?} with parent {:?}",
|
debug!("Inserting into cache: {:?} with parent {:?}",
|
||||||
element.as_node().to_unsafe(), parent.as_node().to_unsafe());
|
element, parent);
|
||||||
|
|
||||||
self.cache.insert(StyleSharingCandidate {
|
self.cache.insert(StyleSharingCandidate {
|
||||||
node: element.as_node().to_unsafe(),
|
element: SendElement(*element),
|
||||||
common_style_affecting_attributes: None,
|
common_style_affecting_attributes: None,
|
||||||
class_attributes: None,
|
class_attributes: None,
|
||||||
}, ());
|
}, ());
|
||||||
|
@ -392,7 +394,7 @@ trait PrivateMatchMethods: TElement {
|
||||||
/// Note that animations only apply to nodes or ::before or ::after
|
/// Note that animations only apply to nodes or ::before or ::after
|
||||||
/// pseudo-elements.
|
/// pseudo-elements.
|
||||||
fn cascade_node_pseudo_element<'a>(&self,
|
fn cascade_node_pseudo_element<'a>(&self,
|
||||||
context: &StyleContext,
|
context: &StyleContext<Self>,
|
||||||
parent_style: Option<&Arc<ComputedValues>>,
|
parent_style: Option<&Arc<ComputedValues>>,
|
||||||
old_style: Option<&Arc<ComputedValues>>,
|
old_style: Option<&Arc<ComputedValues>>,
|
||||||
rule_node: &StrongRuleNode,
|
rule_node: &StrongRuleNode,
|
||||||
|
@ -497,18 +499,15 @@ trait PrivateMatchMethods: TElement {
|
||||||
|
|
||||||
fn share_style_with_candidate_if_possible(&self,
|
fn share_style_with_candidate_if_possible(&self,
|
||||||
shared_context: &SharedStyleContext,
|
shared_context: &SharedStyleContext,
|
||||||
candidate: &mut StyleSharingCandidate)
|
candidate: &mut StyleSharingCandidate<Self>)
|
||||||
-> Result<ComputedStyle, CacheMiss> {
|
-> Result<ComputedStyle, CacheMiss> {
|
||||||
let candidate_element = unsafe {
|
let candidate_element = candidate.element.0;
|
||||||
Self::ConcreteNode::from_unsafe(&candidate.node).as_element().unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
element_matches_candidate(self, candidate, &candidate_element,
|
element_matches_candidate(self, candidate, &candidate_element,
|
||||||
shared_context)
|
shared_context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_rule_node(context: &StyleContext,
|
fn compute_rule_node<E: TElement>(context: &StyleContext<E>,
|
||||||
applicable_declarations: &mut Vec<ApplicableDeclarationBlock>)
|
applicable_declarations: &mut Vec<ApplicableDeclarationBlock>)
|
||||||
-> StrongRuleNode
|
-> StrongRuleNode
|
||||||
{
|
{
|
||||||
|
@ -520,7 +519,7 @@ fn compute_rule_node(context: &StyleContext,
|
||||||
impl<E: TElement> PrivateMatchMethods for E {}
|
impl<E: TElement> PrivateMatchMethods for E {}
|
||||||
|
|
||||||
pub trait MatchMethods : TElement {
|
pub trait MatchMethods : TElement {
|
||||||
fn match_element(&self, context: &StyleContext, parent_bf: Option<&BloomFilter>)
|
fn match_element(&self, context: &StyleContext<Self>, parent_bf: Option<&BloomFilter>)
|
||||||
-> MatchResults
|
-> MatchResults
|
||||||
{
|
{
|
||||||
let mut applicable_declarations: Vec<ApplicableDeclarationBlock> = Vec::with_capacity(16);
|
let mut applicable_declarations: Vec<ApplicableDeclarationBlock> = Vec::with_capacity(16);
|
||||||
|
@ -569,7 +568,7 @@ pub trait MatchMethods : TElement {
|
||||||
/// guarantee that at the type system level yet.
|
/// guarantee that at the type system level yet.
|
||||||
unsafe fn share_style_if_possible(&self,
|
unsafe fn share_style_if_possible(&self,
|
||||||
style_sharing_candidate_cache:
|
style_sharing_candidate_cache:
|
||||||
&mut StyleSharingCandidateCache,
|
&mut StyleSharingCandidateCache<Self>,
|
||||||
shared_context: &SharedStyleContext,
|
shared_context: &SharedStyleContext,
|
||||||
data: &mut AtomicRefMut<ElementData>)
|
data: &mut AtomicRefMut<ElementData>)
|
||||||
-> StyleSharingResult {
|
-> StyleSharingResult {
|
||||||
|
@ -718,7 +717,7 @@ pub trait MatchMethods : TElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn cascade_node(&self,
|
unsafe fn cascade_node(&self,
|
||||||
context: &StyleContext,
|
context: &StyleContext<Self>,
|
||||||
mut data: &mut AtomicRefMut<ElementData>,
|
mut data: &mut AtomicRefMut<ElementData>,
|
||||||
parent: Option<Self>,
|
parent: Option<Self>,
|
||||||
primary_rule_node: StrongRuleNode,
|
primary_rule_node: StrongRuleNode,
|
||||||
|
@ -795,7 +794,7 @@ pub trait MatchMethods : TElement {
|
||||||
mut old_pseudos: Option<&mut PseudoStyles>,
|
mut old_pseudos: Option<&mut PseudoStyles>,
|
||||||
new_primary: &Arc<ComputedValues>,
|
new_primary: &Arc<ComputedValues>,
|
||||||
new_pseudos: &mut PseudoStyles,
|
new_pseudos: &mut PseudoStyles,
|
||||||
context: &StyleContext,
|
context: &StyleContext<Self>,
|
||||||
mut pseudo_rule_nodes: PseudoRuleNodes,
|
mut pseudo_rule_nodes: PseudoRuleNodes,
|
||||||
possibly_expired_animations: &mut Vec<PropertyAnimation>)
|
possibly_expired_animations: &mut Vec<PropertyAnimation>)
|
||||||
-> RestyleDamage
|
-> RestyleDamage
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
use dom::{OpaqueNode, TElement, TNode, UnsafeNode};
|
use dom::{OpaqueNode, TElement, TNode, UnsafeNode};
|
||||||
use rayon;
|
use rayon;
|
||||||
|
use scoped_tls::ScopedTLS;
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
use std::borrow::Borrow;
|
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use traversal::{DomTraversal, PerLevelTraversalData, PreTraverseToken};
|
use traversal::{DomTraversal, PerLevelTraversalData, PreTraverseToken};
|
||||||
use traversal::{STYLE_SHARING_CACHE_HITS, STYLE_SHARING_CACHE_MISSES};
|
use traversal::{STYLE_SHARING_CACHE_HITS, STYLE_SHARING_CACHE_MISSES};
|
||||||
|
@ -45,14 +45,15 @@ pub fn traverse_dom<N, D>(traversal: &D,
|
||||||
(vec![root.as_node().to_unsafe()], known_root_dom_depth)
|
(vec![root.as_node().to_unsafe()], known_root_dom_depth)
|
||||||
};
|
};
|
||||||
|
|
||||||
let data = PerLevelTraversalData {
|
let traversal_data = PerLevelTraversalData {
|
||||||
current_dom_depth: depth,
|
current_dom_depth: depth,
|
||||||
};
|
};
|
||||||
|
let tls = ScopedTLS::<D::ThreadLocalContext>::new(queue);
|
||||||
let root = root.as_node().opaque();
|
let root = root.as_node().opaque();
|
||||||
|
|
||||||
queue.install(|| {
|
queue.install(|| {
|
||||||
rayon::scope(|scope| {
|
rayon::scope(|scope| {
|
||||||
traverse_nodes(nodes, root, data, scope, traversal);
|
traverse_nodes(nodes, root, traversal_data, scope, traversal, &tls);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -71,20 +72,26 @@ pub fn traverse_dom<N, D>(traversal: &D,
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn top_down_dom<'a, 'scope, N, D>(unsafe_nodes: &'a [UnsafeNode],
|
fn top_down_dom<'a, 'scope, N, D>(unsafe_nodes: &'a [UnsafeNode],
|
||||||
root: OpaqueNode,
|
root: OpaqueNode,
|
||||||
mut data: PerLevelTraversalData,
|
mut traversal_data: PerLevelTraversalData,
|
||||||
scope: &'a rayon::Scope<'scope>,
|
scope: &'a rayon::Scope<'scope>,
|
||||||
traversal: &'scope D)
|
traversal: &'scope D,
|
||||||
|
tls: &'scope ScopedTLS<'scope, D::ThreadLocalContext>)
|
||||||
where N: TNode,
|
where N: TNode,
|
||||||
D: DomTraversal<N>,
|
D: DomTraversal<N>,
|
||||||
{
|
{
|
||||||
let mut discovered_child_nodes = vec![];
|
let mut discovered_child_nodes = vec![];
|
||||||
|
{
|
||||||
|
// Scope the borrow of the TLS so that the borrow is dropped before
|
||||||
|
// potentially traversing a child on this thread.
|
||||||
|
let mut tlc = tls.ensure(|| traversal.create_thread_local_context());
|
||||||
|
|
||||||
for unsafe_node in unsafe_nodes {
|
for unsafe_node in unsafe_nodes {
|
||||||
// Get a real layout node.
|
// Get a real layout node.
|
||||||
let node = unsafe { N::from_unsafe(&unsafe_node) };
|
let node = unsafe { N::from_unsafe(&unsafe_node) };
|
||||||
|
|
||||||
// Perform the appropriate traversal.
|
// Perform the appropriate traversal.
|
||||||
let mut children_to_process = 0isize;
|
let mut children_to_process = 0isize;
|
||||||
traversal.process_preorder(node, &mut data);
|
traversal.process_preorder(&mut traversal_data, &mut *tlc, node);
|
||||||
if let Some(el) = node.as_element() {
|
if let Some(el) = node.as_element() {
|
||||||
D::traverse_children(el, |kid| {
|
D::traverse_children(el, |kid| {
|
||||||
children_to_process += 1;
|
children_to_process += 1;
|
||||||
|
@ -97,7 +104,7 @@ fn top_down_dom<'a, 'scope, N, D>(unsafe_nodes: &'a [UnsafeNode],
|
||||||
if D::needs_postorder_traversal() {
|
if D::needs_postorder_traversal() {
|
||||||
if children_to_process == 0 {
|
if children_to_process == 0 {
|
||||||
// If there were no more children, start walking back up.
|
// If there were no more children, start walking back up.
|
||||||
bottom_up_dom(root, *unsafe_node, traversal)
|
bottom_up_dom(traversal, &mut *tlc, root, *unsafe_node)
|
||||||
} else {
|
} else {
|
||||||
// Otherwise record the number of children to process when the
|
// Otherwise record the number of children to process when the
|
||||||
// time comes.
|
// time comes.
|
||||||
|
@ -105,23 +112,20 @@ fn top_down_dom<'a, 'scope, N, D>(unsafe_nodes: &'a [UnsafeNode],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NB: In parallel traversal mode we have to purge the LRU cache in order to
|
if let Some(ref mut depth) = traversal_data.current_dom_depth {
|
||||||
// be able to access it without races.
|
|
||||||
let tlc = traversal.create_or_get_thread_local_context();
|
|
||||||
(*tlc).borrow().style_sharing_candidate_cache.borrow_mut().clear();
|
|
||||||
|
|
||||||
if let Some(ref mut depth) = data.current_dom_depth {
|
|
||||||
*depth += 1;
|
*depth += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
traverse_nodes(discovered_child_nodes, root, data, scope, traversal);
|
traverse_nodes(discovered_child_nodes, root, traversal_data, scope, traversal, tls);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn traverse_nodes<'a, 'scope, N, D>(nodes: Vec<UnsafeNode>, root: OpaqueNode,
|
fn traverse_nodes<'a, 'scope, N, D>(nodes: Vec<UnsafeNode>, root: OpaqueNode,
|
||||||
data: PerLevelTraversalData,
|
traversal_data: PerLevelTraversalData,
|
||||||
scope: &'a rayon::Scope<'scope>,
|
scope: &'a rayon::Scope<'scope>,
|
||||||
traversal: &'scope D)
|
traversal: &'scope D,
|
||||||
|
tls: &'scope ScopedTLS<'scope, D::ThreadLocalContext>)
|
||||||
where N: TNode,
|
where N: TNode,
|
||||||
D: DomTraversal<N>,
|
D: DomTraversal<N>,
|
||||||
{
|
{
|
||||||
|
@ -133,17 +137,17 @@ fn traverse_nodes<'a, 'scope, N, D>(nodes: Vec<UnsafeNode>, root: OpaqueNode,
|
||||||
// we're only pushing one work unit.
|
// we're only pushing one work unit.
|
||||||
if nodes.len() <= CHUNK_SIZE {
|
if nodes.len() <= CHUNK_SIZE {
|
||||||
let nodes = nodes.into_boxed_slice();
|
let nodes = nodes.into_boxed_slice();
|
||||||
top_down_dom(&nodes, root, data, scope, traversal);
|
top_down_dom(&nodes, root, traversal_data, scope, traversal, tls);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// General case.
|
// General case.
|
||||||
for chunk in nodes.chunks(CHUNK_SIZE) {
|
for chunk in nodes.chunks(CHUNK_SIZE) {
|
||||||
let nodes = chunk.iter().cloned().collect::<Vec<_>>().into_boxed_slice();
|
let nodes = chunk.iter().cloned().collect::<Vec<_>>().into_boxed_slice();
|
||||||
let data = data.clone();
|
let traversal_data = traversal_data.clone();
|
||||||
scope.spawn(move |scope| {
|
scope.spawn(move |scope| {
|
||||||
let nodes = nodes;
|
let nodes = nodes;
|
||||||
top_down_dom(&nodes, root, data, scope, traversal)
|
top_down_dom(&nodes, root, traversal_data, scope, traversal, tls)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,9 +164,10 @@ fn traverse_nodes<'a, 'scope, N, D>(nodes: Vec<UnsafeNode>, root: OpaqueNode,
|
||||||
/// The only communication between siblings is that they both
|
/// The only communication between siblings is that they both
|
||||||
/// fetch-and-subtract the parent's children count.
|
/// fetch-and-subtract the parent's children count.
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn bottom_up_dom<N, D>(root: OpaqueNode,
|
fn bottom_up_dom<N, D>(traversal: &D,
|
||||||
unsafe_node: UnsafeNode,
|
thread_local: &mut D::ThreadLocalContext,
|
||||||
traversal: &D)
|
root: OpaqueNode,
|
||||||
|
unsafe_node: UnsafeNode)
|
||||||
where N: TNode,
|
where N: TNode,
|
||||||
D: DomTraversal<N>
|
D: DomTraversal<N>
|
||||||
{
|
{
|
||||||
|
@ -170,7 +175,7 @@ fn bottom_up_dom<N, D>(root: OpaqueNode,
|
||||||
let mut node = unsafe { N::from_unsafe(&unsafe_node) };
|
let mut node = unsafe { N::from_unsafe(&unsafe_node) };
|
||||||
loop {
|
loop {
|
||||||
// Perform the appropriate operation.
|
// Perform the appropriate operation.
|
||||||
traversal.process_postorder(node);
|
traversal.process_postorder(thread_local, node);
|
||||||
|
|
||||||
if node.opaque() == root {
|
if node.opaque() == root {
|
||||||
break;
|
break;
|
||||||
|
|
51
components/style/scoped_tls.rs
Normal file
51
components/style/scoped_tls.rs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#![allow(unsafe_code)]
|
||||||
|
|
||||||
|
use rayon;
|
||||||
|
use std::cell::{Ref, RefCell, RefMut};
|
||||||
|
|
||||||
|
/// Stack-scoped thread-local storage for rayon thread pools.
|
||||||
|
|
||||||
|
pub struct ScopedTLS<'a, T: Send> {
|
||||||
|
pool: &'a rayon::ThreadPool,
|
||||||
|
slots: Box<[RefCell<Option<T>>]>,
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl<'a, T: Send> Sync for ScopedTLS<'a, T> {}
|
||||||
|
|
||||||
|
impl<'a, T: Send> ScopedTLS<'a, T> {
|
||||||
|
pub fn new(p: &'a rayon::ThreadPool) -> Self {
|
||||||
|
let count = p.num_threads();
|
||||||
|
let mut v = Vec::with_capacity(count);
|
||||||
|
for _ in 0..count {
|
||||||
|
v.push(RefCell::new(None));
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedTLS {
|
||||||
|
pool: p,
|
||||||
|
slots: v.into_boxed_slice(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn borrow(&self) -> Ref<Option<T>> {
|
||||||
|
let idx = self.pool.current_thread_index().unwrap();
|
||||||
|
self.slots[idx].borrow()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn borrow_mut(&self) -> RefMut<Option<T>> {
|
||||||
|
let idx = self.pool.current_thread_index().unwrap();
|
||||||
|
self.slots[idx].borrow_mut()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ensure<F: FnOnce() -> T>(&self, f: F) -> RefMut<T> {
|
||||||
|
let mut opt = self.borrow_mut();
|
||||||
|
if opt.is_none() {
|
||||||
|
*opt = Some(f());
|
||||||
|
}
|
||||||
|
|
||||||
|
RefMut::map(opt, |x| x.as_mut().unwrap())
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,6 @@
|
||||||
//! Implements sequential traversal over the DOM tree.
|
//! Implements sequential traversal over the DOM tree.
|
||||||
|
|
||||||
use dom::{TElement, TNode};
|
use dom::{TElement, TNode};
|
||||||
use std::borrow::Borrow;
|
|
||||||
use traversal::{DomTraversal, PerLevelTraversalData, PreTraverseToken};
|
use traversal::{DomTraversal, PerLevelTraversalData, PreTraverseToken};
|
||||||
|
|
||||||
pub fn traverse_dom<N, D>(traversal: &D,
|
pub fn traverse_dom<N, D>(traversal: &D,
|
||||||
|
@ -16,43 +15,41 @@ pub fn traverse_dom<N, D>(traversal: &D,
|
||||||
{
|
{
|
||||||
debug_assert!(token.should_traverse());
|
debug_assert!(token.should_traverse());
|
||||||
|
|
||||||
fn doit<N, D>(traversal: &D, node: N, data: &mut PerLevelTraversalData)
|
fn doit<N, D>(traversal: &D, traversal_data: &mut PerLevelTraversalData,
|
||||||
|
thread_local: &mut D::ThreadLocalContext, node: N)
|
||||||
where N: TNode,
|
where N: TNode,
|
||||||
D: DomTraversal<N>
|
D: DomTraversal<N>
|
||||||
{
|
{
|
||||||
traversal.process_preorder(node, data);
|
traversal.process_preorder(traversal_data, thread_local, node);
|
||||||
if let Some(el) = node.as_element() {
|
if let Some(el) = node.as_element() {
|
||||||
if let Some(ref mut depth) = data.current_dom_depth {
|
if let Some(ref mut depth) = traversal_data.current_dom_depth {
|
||||||
*depth += 1;
|
*depth += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
D::traverse_children(el, |kid| doit(traversal, kid, data));
|
D::traverse_children(el, |kid| doit(traversal, traversal_data, thread_local, kid));
|
||||||
|
|
||||||
if let Some(ref mut depth) = data.current_dom_depth {
|
if let Some(ref mut depth) = traversal_data.current_dom_depth {
|
||||||
*depth -= 1;
|
*depth -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if D::needs_postorder_traversal() {
|
if D::needs_postorder_traversal() {
|
||||||
traversal.process_postorder(node);
|
traversal.process_postorder(thread_local, node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut data = PerLevelTraversalData {
|
let mut traversal_data = PerLevelTraversalData {
|
||||||
current_dom_depth: None,
|
current_dom_depth: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut tlc = traversal.create_thread_local_context();
|
||||||
if token.traverse_unstyled_children_only() {
|
if token.traverse_unstyled_children_only() {
|
||||||
for kid in root.as_node().children() {
|
for kid in root.as_node().children() {
|
||||||
if kid.as_element().map_or(false, |el| el.get_data().is_none()) {
|
if kid.as_element().map_or(false, |el| el.get_data().is_none()) {
|
||||||
doit(traversal, kid, &mut data);
|
doit(traversal, &mut traversal_data, &mut tlc, kid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
doit(traversal, root.as_node(), &mut data);
|
doit(traversal, &mut traversal_data, &mut tlc, root.as_node());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the local LRU cache since we store stateful elements inside.
|
|
||||||
let tlc = traversal.create_or_get_thread_local_context();
|
|
||||||
(*tlc).borrow().style_sharing_candidate_cache.borrow_mut().clear();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
use atomic_refcell::{AtomicRefCell, AtomicRefMut};
|
use atomic_refcell::{AtomicRefCell, AtomicRefMut};
|
||||||
use bloom::StyleBloom;
|
use bloom::StyleBloom;
|
||||||
use context::{SharedStyleContext, StyleContext, ThreadLocalStyleContext};
|
use context::{SharedStyleContext, StyleContext};
|
||||||
use data::{ElementData, StoredRestyleHint};
|
use data::{ElementData, StoredRestyleHint};
|
||||||
use dom::{OpaqueNode, TElement, TNode};
|
use dom::{OpaqueNode, TElement, TNode};
|
||||||
use matching::{MatchMethods, StyleSharingResult};
|
use matching::{MatchMethods, StyleSharingResult};
|
||||||
|
@ -15,10 +15,8 @@ use selector_parser::RestyleDamage;
|
||||||
use selectors::Element;
|
use selectors::Element;
|
||||||
use selectors::matching::StyleRelations;
|
use selectors::matching::StyleRelations;
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
use std::borrow::Borrow;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::rc::Rc;
|
|
||||||
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
|
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
|
||||||
use stylist::Stylist;
|
use stylist::Stylist;
|
||||||
|
|
||||||
|
@ -128,15 +126,16 @@ impl LogBehavior {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait DomTraversal<N: TNode> : Sync {
|
pub trait DomTraversal<N: TNode> : Sync {
|
||||||
type ThreadLocalContext: Borrow<ThreadLocalStyleContext>;
|
type ThreadLocalContext: Send;
|
||||||
|
|
||||||
/// Process `node` on the way down, before its children have been processed.
|
/// Process `node` on the way down, before its children have been processed.
|
||||||
fn process_preorder(&self, node: N, data: &mut PerLevelTraversalData);
|
fn process_preorder(&self, data: &mut PerLevelTraversalData,
|
||||||
|
thread_local: &mut Self::ThreadLocalContext, node: N);
|
||||||
|
|
||||||
/// Process `node` on the way up, after its children have been processed.
|
/// Process `node` on the way up, after its children have been processed.
|
||||||
///
|
///
|
||||||
/// This is only executed if `needs_postorder_traversal` returns true.
|
/// This is only executed if `needs_postorder_traversal` returns true.
|
||||||
fn process_postorder(&self, node: N);
|
fn process_postorder(&self, thread_local: &mut Self::ThreadLocalContext, node: N);
|
||||||
|
|
||||||
/// Boolean that specifies whether a bottom up traversal should be
|
/// Boolean that specifies whether a bottom up traversal should be
|
||||||
/// performed.
|
/// performed.
|
||||||
|
@ -321,7 +320,7 @@ pub trait DomTraversal<N: TNode> : Sync {
|
||||||
|
|
||||||
fn shared_context(&self) -> &SharedStyleContext;
|
fn shared_context(&self) -> &SharedStyleContext;
|
||||||
|
|
||||||
fn create_or_get_thread_local_context(&self) -> Rc<Self::ThreadLocalContext>;
|
fn create_thread_local_context(&self) -> Self::ThreadLocalContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines the amount of relations where we're going to share style.
|
/// Determines the amount of relations where we're going to share style.
|
||||||
|
@ -337,7 +336,7 @@ pub fn relations_are_shareable(relations: &StyleRelations) -> bool {
|
||||||
|
|
||||||
/// Handles lazy resolution of style in display:none subtrees. See the comment
|
/// Handles lazy resolution of style in display:none subtrees. See the comment
|
||||||
/// at the callsite in query.rs.
|
/// at the callsite in query.rs.
|
||||||
pub fn style_element_in_display_none_subtree<E, F>(context: &StyleContext,
|
pub fn style_element_in_display_none_subtree<E, F>(context: &StyleContext<E>,
|
||||||
element: E, init_data: &F) -> E
|
element: E, init_data: &F) -> E
|
||||||
where E: TElement,
|
where E: TElement,
|
||||||
F: Fn(E),
|
F: Fn(E),
|
||||||
|
@ -376,7 +375,7 @@ pub fn style_element_in_display_none_subtree<E, F>(context: &StyleContext,
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn recalc_style_at<E, D>(traversal: &D,
|
pub fn recalc_style_at<E, D>(traversal: &D,
|
||||||
traversal_data: &mut PerLevelTraversalData,
|
traversal_data: &mut PerLevelTraversalData,
|
||||||
context: &StyleContext,
|
context: &mut StyleContext<E>,
|
||||||
element: E,
|
element: E,
|
||||||
mut data: &mut AtomicRefMut<ElementData>)
|
mut data: &mut AtomicRefMut<ElementData>)
|
||||||
where E: TElement,
|
where E: TElement,
|
||||||
|
@ -423,7 +422,7 @@ pub fn recalc_style_at<E, D>(traversal: &D,
|
||||||
// since we have separate bits for each now.
|
// since we have separate bits for each now.
|
||||||
fn compute_style<E, D>(_traversal: &D,
|
fn compute_style<E, D>(_traversal: &D,
|
||||||
traversal_data: &mut PerLevelTraversalData,
|
traversal_data: &mut PerLevelTraversalData,
|
||||||
context: &StyleContext,
|
context: &mut StyleContext<E>,
|
||||||
element: E,
|
element: E,
|
||||||
mut data: &mut AtomicRefMut<ElementData>) -> bool
|
mut data: &mut AtomicRefMut<ElementData>) -> bool
|
||||||
where E: TElement,
|
where E: TElement,
|
||||||
|
@ -445,13 +444,10 @@ fn compute_style<E, D>(_traversal: &D,
|
||||||
bf.assert_complete(element);
|
bf.assert_complete(element);
|
||||||
|
|
||||||
// Check to see whether we can share a style with someone.
|
// Check to see whether we can share a style with someone.
|
||||||
let mut style_sharing_candidate_cache =
|
|
||||||
context.thread_local.style_sharing_candidate_cache.borrow_mut();
|
|
||||||
|
|
||||||
let sharing_result = if element.parent_element().is_none() {
|
let sharing_result = if element.parent_element().is_none() {
|
||||||
StyleSharingResult::CannotShare
|
StyleSharingResult::CannotShare
|
||||||
} else {
|
} else {
|
||||||
unsafe { element.share_style_if_possible(&mut style_sharing_candidate_cache,
|
unsafe { element.share_style_if_possible(&mut context.thread_local.style_sharing_candidate_cache,
|
||||||
shared_context, &mut data) }
|
shared_context, &mut data) }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -486,16 +482,16 @@ fn compute_style<E, D>(_traversal: &D,
|
||||||
|
|
||||||
// Add ourselves to the LRU cache.
|
// Add ourselves to the LRU cache.
|
||||||
if let Some(element) = shareable_element {
|
if let Some(element) = shareable_element {
|
||||||
style_sharing_candidate_cache.insert_if_possible(&element,
|
context.thread_local
|
||||||
&data.styles().primary.values,
|
.style_sharing_candidate_cache
|
||||||
relations);
|
.insert_if_possible(&element, &data.styles().primary.values, relations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StyleSharingResult::StyleWasShared(index) => {
|
StyleSharingResult::StyleWasShared(index) => {
|
||||||
if opts::get().style_sharing_stats {
|
if opts::get().style_sharing_stats {
|
||||||
STYLE_SHARING_CACHE_HITS.fetch_add(1, Ordering::Relaxed);
|
STYLE_SHARING_CACHE_HITS.fetch_add(1, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
style_sharing_candidate_cache.touch(index);
|
context.thread_local.style_sharing_candidate_cache.touch(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,11 @@ use std::ptr;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use style::arc_ptr_eq;
|
use style::arc_ptr_eq;
|
||||||
use style::atomic_refcell::AtomicRefMut;
|
use style::atomic_refcell::AtomicRefMut;
|
||||||
use style::context::{ThreadLocalStyleContextCreationInfo, QuirksMode, ReflowGoal, SharedStyleContext, StyleContext};
|
use style::context::{QuirksMode, ReflowGoal, SharedStyleContext, StyleContext};
|
||||||
|
use style::context::{ThreadLocalStyleContext, ThreadLocalStyleContextCreationInfo};
|
||||||
use style::data::{ElementData, RestyleData};
|
use style::data::{ElementData, RestyleData};
|
||||||
use style::dom::{ShowSubtreeData, TElement, TNode};
|
use style::dom::{ShowSubtreeData, TElement, TNode};
|
||||||
use style::error_reporting::StdoutErrorReporter;
|
use style::error_reporting::StdoutErrorReporter;
|
||||||
use style::gecko::context::clear_local_context;
|
|
||||||
use style::gecko::data::{NUM_THREADS, PerDocumentStyleData, PerDocumentStyleDataImpl};
|
use style::gecko::data::{NUM_THREADS, PerDocumentStyleData, PerDocumentStyleDataImpl};
|
||||||
use style::gecko::restyle_damage::GeckoRestyleDamage;
|
use style::gecko::restyle_damage::GeckoRestyleDamage;
|
||||||
use style::gecko::selector_parser::{SelectorImpl, PseudoElement};
|
use style::gecko::selector_parser::{SelectorImpl, PseudoElement};
|
||||||
|
@ -88,12 +88,6 @@ pub extern "C" fn Servo_Initialize() -> () {
|
||||||
pub extern "C" fn Servo_Shutdown() -> () {
|
pub extern "C" fn Servo_Shutdown() -> () {
|
||||||
// Destroy our default computed values.
|
// Destroy our default computed values.
|
||||||
unsafe { ComputedValues::shutdown(); }
|
unsafe { ComputedValues::shutdown(); }
|
||||||
|
|
||||||
// In general, ThreadLocalStyleContexts will get destroyed when the worker thread
|
|
||||||
// is joined and the TLS is dropped. However, under some configurations we
|
|
||||||
// may do sequential style computation on the main thread, so we need to be
|
|
||||||
// sure to clear the main thread TLS entry as well.
|
|
||||||
clear_local_context();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_shared_context(mut per_doc_data: &mut AtomicRefMut<PerDocumentStyleDataImpl>) -> SharedStyleContext {
|
fn create_shared_context(mut per_doc_data: &mut AtomicRefMut<PerDocumentStyleDataImpl>) -> SharedStyleContext {
|
||||||
|
@ -875,21 +869,18 @@ pub extern "C" fn Servo_ResolveStyle(element: RawGeckoElementBorrowed,
|
||||||
let mut per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
let mut per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||||
let shared_style_context = create_shared_context(&mut per_doc_data);
|
let shared_style_context = create_shared_context(&mut per_doc_data);
|
||||||
let traversal = RecalcStyleOnly::new(shared_style_context);
|
let traversal = RecalcStyleOnly::new(shared_style_context);
|
||||||
let tlc = traversal.create_or_get_thread_local_context();
|
|
||||||
|
|
||||||
let mut traversal_data = PerLevelTraversalData {
|
let mut traversal_data = PerLevelTraversalData {
|
||||||
current_dom_depth: None,
|
current_dom_depth: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let context = StyleContext {
|
let mut tlc = ThreadLocalStyleContext::new(traversal.shared_context());
|
||||||
|
let mut context = StyleContext {
|
||||||
shared: traversal.shared_context(),
|
shared: traversal.shared_context(),
|
||||||
thread_local: &*tlc,
|
thread_local: &mut tlc,
|
||||||
};
|
};
|
||||||
|
|
||||||
recalc_style_at(&traversal, &mut traversal_data, &context, element, &mut data);
|
recalc_style_at(&traversal, &mut traversal_data, &mut context, element, &mut data);
|
||||||
|
|
||||||
// We don't want to keep any cached style around after this one-off style resolution.
|
|
||||||
tlc.style_sharing_candidate_cache.borrow_mut().clear();
|
|
||||||
|
|
||||||
// The element was either unstyled or needed restyle. If it was unstyled, it may have
|
// The element was either unstyled or needed restyle. If it was unstyled, it may have
|
||||||
// additional unstyled children that subsequent traversals won't find now that the style
|
// additional unstyled children that subsequent traversals won't find now that the style
|
||||||
|
|
|
@ -11,7 +11,7 @@ lint-scripts = [
|
||||||
|
|
||||||
[ignore]
|
[ignore]
|
||||||
# Ignored packages with duplicated versions
|
# Ignored packages with duplicated versions
|
||||||
packages = ["bitflags", "lazy_static", "semver"]
|
packages = ["bitflags", "lazy_static", "semver", "rayon"]
|
||||||
# Files that are ignored for all tidy and lint checks.
|
# Files that are ignored for all tidy and lint checks.
|
||||||
files = [
|
files = [
|
||||||
# Generated and upstream code combined with our own. Could use cleanup
|
# Generated and upstream code combined with our own. Could use cleanup
|
||||||
|
|
|
@ -20,7 +20,7 @@ html5ever-atoms = "0.1"
|
||||||
matches = "0.1"
|
matches = "0.1"
|
||||||
owning_ref = "0.2.2"
|
owning_ref = "0.2.2"
|
||||||
parking_lot = "0.3"
|
parking_lot = "0.3"
|
||||||
rayon = "0.5"
|
rayon = "0.6"
|
||||||
rustc-serialize = "0.3"
|
rustc-serialize = "0.3"
|
||||||
selectors = "0.15"
|
selectors = "0.15"
|
||||||
servo_atoms = {path = "../../../components/atoms"}
|
servo_atoms = {path = "../../../components/atoms"}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue