From 73917cce83d2225b51b29c374d861d71ec69435f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 7 Oct 2016 12:22:06 +0200 Subject: style: Use rayon instead of our custom work queue. --- components/layout_thread/Cargo.toml | 1 + components/layout_thread/lib.rs | 29 ++++++++--------------------- 2 files changed, 9 insertions(+), 21 deletions(-) (limited to 'components/layout_thread') diff --git a/components/layout_thread/Cargo.toml b/components/layout_thread/Cargo.toml index cc97c74697f..798abe3eb03 100644 --- a/components/layout_thread/Cargo.toml +++ b/components/layout_thread/Cargo.toml @@ -27,6 +27,7 @@ net_traits = {path = "../net_traits"} parking_lot = {version = "0.3.3", features = ["nightly"]} plugins = {path = "../plugins"} profile_traits = {path = "../profile_traits"} +rayon = "0.5" script = {path = "../script"} script_layout_interface = {path = "../script_layout_interface"} script_traits = {path = "../script_traits"} diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 859183935b1..ce08a1ab010 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -34,6 +34,7 @@ extern crate net_traits; extern crate parking_lot; #[macro_use] extern crate profile_traits; +extern crate rayon; extern crate script; extern crate script_layout_interface; extern crate script_traits; @@ -107,14 +108,12 @@ use style::dom::{TDocument, TElement, TNode}; use style::error_reporting::{ParseErrorReporter, StdoutErrorReporter}; use style::logical_geometry::LogicalPoint; use style::media_queries::{Device, MediaType}; -use style::parallel::WorkQueueData; use style::parser::ParserContextExtraData; use style::selector_matching::Stylist; use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION, STORE_OVERFLOW}; use style::stylesheets::{Origin, Stylesheet, UserAgentStylesheets}; use style::thread_state; use style::timer::Timer; -use style::workqueue::WorkQueue; use url::Url; use util::geometry::max_rect; use util::opts; @@ -173,7 +172,7 @@ pub struct LayoutThread { first_reflow: bool, /// The workers that we use for parallel operation. - parallel_traversal: Option>, + parallel_traversal: Option, /// Starts at zero, and increased by one every time a layout completes. /// This can be used to easily check for invalid stale data. @@ -383,7 +382,9 @@ impl LayoutThread { MediaType::Screen, opts::get().initial_window_size.to_f32() * ScaleFactor::new(1.0)); let parallel_traversal = if layout_threads != 1 { - WorkQueue::new("LayoutWorker", thread_state::LAYOUT, layout_threads).ok() + let configuration = + rayon::Configuration::new().set_num_threads(layout_threads); + rayon::ThreadPool::new(configuration).ok() } else { None }; @@ -711,19 +712,6 @@ impl LayoutThread { size: heap_size_of_local_context(), }); - // ... as do each of the LayoutWorkers, if present. - if let Some(ref traversal) = self.parallel_traversal { - let sizes = traversal.heap_size_of_tls(heap_size_of_local_context); - for (i, size) in sizes.iter().enumerate() { - reports.push(Report { - path: path![formatted_url, - format!("layout-worker-{}-local-context", i)], - kind: ReportKind::ExplicitJemallocHeapSize, - size: *size, - }); - } - } - reports_chan.send(reports); } @@ -773,9 +761,8 @@ impl LayoutThread { /// Shuts down the layout thread now. If there are any DOM nodes left, layout will now (safely) /// crash. fn exit_now(&mut self) { - if let Some(ref mut traversal) = self.parallel_traversal { - traversal.shutdown() - } + // Drop the rayon threadpool if present. + let _ = self.parallel_traversal.take(); } fn handle_add_stylesheet<'a, 'b>(&self, @@ -855,7 +842,7 @@ impl LayoutThread { /// This corresponds to `Reflow()` in Gecko and `layout()` in WebKit/Blink and should be /// benchmarked against those two. It is marked `#[inline(never)]` to aid profiling. #[inline(never)] - fn solve_constraints_parallel(traversal: &mut WorkQueue, + fn solve_constraints_parallel(traversal: &rayon::ThreadPool, layout_root: &mut Flow, profiler_metadata: Option, time_profiler_chan: time::ProfilerChan, -- cgit v1.2.3