From 18baf5ec7849acf8931d94c643a2b1ae85ca0d7f Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 17 May 2017 18:48:08 +0200 Subject: [PATCH 1/2] Only use the parallel traversal when traversing from the root. --- ports/geckolib/glue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index b18454320f7..afbb8c7ef57 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -217,7 +217,7 @@ fn traverse_subtree(element: GeckoElement, }; let traversal = RecalcStyleOnly::new(shared_style_context, traversal_driver); - if traversal_driver.is_parallel() { + if traversal_driver.is_parallel() && element.is_root() { parallel::traverse_dom(&traversal, element, token, global_style_data.style_thread_pool.as_ref().unwrap()); } else { From 5a28c87b8eefe27542bf27f7fff3eac52e907fba Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Thu, 18 May 2017 14:01:12 +0200 Subject: [PATCH 2/2] Allow forcing a style threadpool of size 1. --- components/style/gecko/global_style_data.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/components/style/gecko/global_style_data.rs b/components/style/gecko/global_style_data.rs index 3cbace9b90a..2ba8749e24f 100644 --- a/components/style/gecko/global_style_data.rs +++ b/components/style/gecko/global_style_data.rs @@ -57,12 +57,25 @@ lazy_static! { pub static ref GLOBAL_STYLE_DATA: GlobalStyleData = { let stylo_threads = env::var("STYLO_THREADS") .map(|s| s.parse::().expect("invalid STYLO_THREADS value")); - let num_threads = match stylo_threads { + let mut num_threads = match stylo_threads { Ok(num) => num, _ => cmp::max(num_cpus::get() * 3 / 4, 1), }; - let pool = if num_threads <= 1 { + // If num_threads is one, there's no point in creating a thread pool, so + // force it to zero. + // + // We allow developers to force a one-thread pool for testing via a + // special environmental variable. + if num_threads == 1 { + let force_pool = env::var("FORCE_STYLO_THREAD_POOL") + .ok().map_or(false, |s| s.parse::().expect("invalid FORCE_STYLO_THREAD_POOL value") == 1); + if !force_pool { + num_threads = 0; + } + } + + let pool = if num_threads < 1 { None } else { let configuration = rayon::Configuration::new()