aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/parallel.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <ecoal95@gmail.com>2016-10-07 12:22:06 +0200
committerEmilio Cobos Álvarez <ecoal95@gmail.com>2016-11-14 21:24:19 +0100
commit73917cce83d2225b51b29c374d861d71ec69435f (patch)
treeac8c6b562ca3e88a7d853ddcab88d114362559e7 /components/layout/parallel.rs
parentb7eb36fa84e6c6c77727ea2cd02c57f6750dc7af (diff)
downloadservo-73917cce83d2225b51b29c374d861d71ec69435f.tar.gz
servo-73917cce83d2225b51b29c374d861d71ec69435f.zip
style: Use rayon instead of our custom work queue.
Diffstat (limited to 'components/layout/parallel.rs')
-rw-r--r--components/layout/parallel.rs90
1 files changed, 50 insertions, 40 deletions
diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs
index 29e53bf9077..03aaa512d3e 100644
--- a/components/layout/parallel.rs
+++ b/components/layout/parallel.rs
@@ -12,12 +12,11 @@ use context::{LayoutContext, SharedLayoutContext};
use flow::{self, Flow, MutableFlowUtils, PostorderFlowTraversal, PreorderFlowTraversal};
use flow_ref::FlowRef;
use profile_traits::time::{self, TimerMetadata, profile};
+use rayon;
use std::mem;
use std::sync::atomic::{AtomicIsize, Ordering};
use style::dom::UnsafeNode;
-use style::parallel::{CHUNK_SIZE, WorkQueueData};
-use style::parallel::run_queue_with_custom_work_data_type;
-use style::workqueue::{WorkQueue, WorkUnit, WorkerProxy};
+use style::parallel::CHUNK_SIZE;
use traversal::{AssignISizes, BubbleISizes};
use traversal::AssignBSizes;
use util::opts;
@@ -50,10 +49,8 @@ pub fn borrowed_flow_to_unsafe_flow(flow: &Flow) -> UnsafeFlow {
}
}
-pub type UnsafeFlowList = (Box<Vec<UnsafeNode>>, usize);
-
-pub type ChunkedFlowTraversalFunction =
- extern "Rust" fn(UnsafeFlowList, &mut WorkerProxy<SharedLayoutContext, UnsafeFlowList>);
+pub type ChunkedFlowTraversalFunction<'scope> =
+ extern "Rust" fn(Box<[UnsafeFlow]>, &'scope SharedLayoutContext, &rayon::Scope<'scope>);
pub type FlowTraversalFunction = extern "Rust" fn(UnsafeFlow, &SharedLayoutContext);
@@ -133,27 +130,35 @@ trait ParallelPostorderFlowTraversal : PostorderFlowTraversal {
/// A parallel top-down flow traversal.
trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
- fn run_parallel(&self,
- unsafe_flows: UnsafeFlowList,
- proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeFlowList>);
+ fn run_parallel<'scope>(&self,
+ unsafe_flows: &[UnsafeFlow],
+ layout_context: &'scope SharedLayoutContext,
+ scope: &rayon::Scope<'scope>);
fn should_record_thread_ids(&self) -> bool;
#[inline(always)]
- fn run_parallel_helper(&self,
- unsafe_flows: UnsafeFlowList,
- proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeFlowList>,
- top_down_func: ChunkedFlowTraversalFunction,
- bottom_up_func: FlowTraversalFunction) {
- let mut discovered_child_flows = Vec::new();
- for unsafe_flow in *unsafe_flows.0 {
+ fn run_parallel_helper<'scope>(&self,
+ unsafe_flows: &[UnsafeFlow],
+ layout_context: &'scope SharedLayoutContext,
+ scope: &rayon::Scope<'scope>,
+ top_down_func: ChunkedFlowTraversalFunction<'scope>,
+ bottom_up_func: FlowTraversalFunction)
+ {
+ let mut discovered_child_flows = vec![];
+ for unsafe_flow in unsafe_flows {
let mut had_children = false;
unsafe {
// Get a real flow.
- let flow: &mut Flow = mem::transmute(unsafe_flow);
+ let flow: &mut Flow = mem::transmute(*unsafe_flow);
if self.should_record_thread_ids() {
- flow::mut_base(flow).thread_id = proxy.worker_index();
+ // FIXME(emilio): With the switch to rayon we can no longer
+ // access a thread id from here easily. Either instrument
+ // rayon (the unstable feature) to get a worker thread
+ // identifier, or remove all the layout tinting mode.
+ //
+ // flow::mut_base(flow).thread_id = proxy.worker_index();
}
if self.should_process(flow) {
@@ -170,25 +175,29 @@ trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
// If there were no more children, start assigning block-sizes.
if !had_children {
- bottom_up_func(unsafe_flow, proxy.user_data())
+ bottom_up_func(*unsafe_flow, layout_context)
}
}
for chunk in discovered_child_flows.chunks(CHUNK_SIZE) {
- proxy.push(WorkUnit {
- fun: top_down_func,
- data: (box chunk.iter().cloned().collect(), 0),
+ let nodes = chunk.iter().cloned().collect::<Vec<_>>().into_boxed_slice();
+
+ scope.spawn(move |scope| {
+ top_down_func(nodes, layout_context, scope);
});
}
}
}
impl<'a> ParallelPreorderFlowTraversal for AssignISizes<'a> {
- fn run_parallel(&self,
- unsafe_flows: UnsafeFlowList,
- proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeFlowList>) {
+ fn run_parallel<'scope>(&self,
+ unsafe_flows: &[UnsafeFlow],
+ layout_context: &'scope SharedLayoutContext,
+ scope: &rayon::Scope<'scope>)
+ {
self.run_parallel_helper(unsafe_flows,
- proxy,
+ layout_context,
+ scope,
assign_inline_sizes,
assign_block_sizes_and_store_overflow)
}
@@ -200,13 +209,13 @@ impl<'a> ParallelPreorderFlowTraversal for AssignISizes<'a> {
impl<'a> ParallelPostorderFlowTraversal for AssignBSizes<'a> {}
-fn assign_inline_sizes(unsafe_flows: UnsafeFlowList,
- proxy: &mut WorkerProxy<SharedLayoutContext, UnsafeFlowList>) {
- let shared_layout_context = proxy.user_data();
+fn assign_inline_sizes<'scope>(unsafe_flows: Box<[UnsafeFlow]>,
+ shared_layout_context: &'scope SharedLayoutContext,
+ scope: &rayon::Scope<'scope>) {
let assign_inline_sizes_traversal = AssignISizes {
shared_context: &shared_layout_context.style_context,
};
- assign_inline_sizes_traversal.run_parallel(unsafe_flows, proxy)
+ assign_inline_sizes_traversal.run_parallel(&unsafe_flows, shared_layout_context, scope)
}
fn assign_block_sizes_and_store_overflow(
@@ -224,20 +233,21 @@ pub fn traverse_flow_tree_preorder(
profiler_metadata: Option<TimerMetadata>,
time_profiler_chan: time::ProfilerChan,
shared_layout_context: &SharedLayoutContext,
- queue: &mut WorkQueue<SharedLayoutContext, WorkQueueData>) {
+ queue: &rayon::ThreadPool) {
if opts::get().bubble_inline_sizes_separately {
let layout_context = LayoutContext::new(shared_layout_context);
let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context };
root.traverse_postorder(&bubble_inline_sizes);
}
- run_queue_with_custom_work_data_type(queue, |queue| {
- profile(time::ProfilerCategory::LayoutParallelWarmup, profiler_metadata,
- time_profiler_chan, || {
- queue.push(WorkUnit {
- fun: assign_inline_sizes,
- data: (box vec![borrowed_flow_to_unsafe_flow(root)], 0),
- })
+ let nodes = vec![borrowed_flow_to_unsafe_flow(root)].into_boxed_slice();
+
+ queue.install(move || {
+ rayon::scope(move |scope| {
+ profile(time::ProfilerCategory::LayoutParallelWarmup,
+ profiler_metadata, time_profiler_chan, move || {
+ assign_inline_sizes(nodes, &shared_layout_context, scope);
+ });
});
- }, shared_layout_context);
+ });
}