From 513833d9b90ead9a0be076c33976d10b8cc34f32 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Fri, 23 Jun 2017 16:03:16 +0900 Subject: [PATCH] Separate thread pool from global state for Gecko When stylo is not enabled in Gecko, the global state initialization still creates the style thread pool, even when it's not going to be used. This wastes address space and a little memory. See https://bugzilla.mozilla.org/show_bug.cgi?id=1374824#c38 and following comment. --- components/style/gecko/global_style_data.rs | 28 +++++++++++++-------- ports/geckolib/glue.rs | 9 ++++--- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/components/style/gecko/global_style_data.rs b/components/style/gecko/global_style_data.rs index 0f80a18816e..f396a4ee451 100644 --- a/components/style/gecko/global_style_data.rs +++ b/components/style/gecko/global_style_data.rs @@ -16,12 +16,6 @@ use std::ffi::CString; /// Global style data pub struct GlobalStyleData { - /// How many threads parallel styling can use. - pub num_threads: usize, - - /// The parallel styling thread pool. - pub style_thread_pool: Option, - /// Shared RWLock for CSSOM objects pub shared_lock: SharedRwLock, @@ -29,6 +23,15 @@ pub struct GlobalStyleData { pub options: StyleSystemOptions, } +/// Global thread pool +pub struct StyleThreadPool { + /// How many threads parallel styling can use. + pub num_threads: usize, + + /// The parallel styling thread pool. + pub style_thread_pool: Option, +} + fn thread_name(index: usize) -> String { format!("StyleThread#{}", index) } @@ -53,8 +56,8 @@ fn thread_shutdown(_: usize) { } lazy_static! { - /// Global style data - pub static ref GLOBAL_STYLE_DATA: GlobalStyleData = { + /// Global thread pool + pub static ref STYLE_THREAD_POOL: StyleThreadPool = { let stylo_threads = env::var("STYLO_THREADS") .map(|s| s.parse::().expect("invalid STYLO_THREADS value")); let mut num_threads = match stylo_threads { @@ -93,11 +96,14 @@ lazy_static! { pool }; - GlobalStyleData { + StyleThreadPool { num_threads: num_threads, style_thread_pool: pool, - shared_lock: SharedRwLock::new(), - options: StyleSystemOptions::default(), } }; + /// Global style data + pub static ref GLOBAL_STYLE_DATA: GlobalStyleData = GlobalStyleData { + shared_lock: SharedRwLock::new(), + options: StyleSystemOptions::default(), + }; } diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 5ef3d30e354..f9f57cb48c3 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -19,7 +19,7 @@ use style::element_state::ElementState; use style::error_reporting::RustLogReporter; use style::font_metrics::{FontMetricsProvider, get_metrics_provider_for_product}; use style::gecko::data::{PerDocumentStyleData, PerDocumentStyleDataImpl}; -use style::gecko::global_style_data::{GLOBAL_STYLE_DATA, GlobalStyleData}; +use style::gecko::global_style_data::{GLOBAL_STYLE_DATA, GlobalStyleData, STYLE_THREAD_POOL}; use style::gecko::restyle_damage::GeckoRestyleDamage; use style::gecko::selector_parser::PseudoElement; use style::gecko::traversal::RecalcStyleOnly; @@ -227,7 +227,8 @@ fn traverse_subtree(element: GeckoElement, debug!("Traversing subtree:"); debug!("{:?}", ShowSubtreeData(element.as_node())); - let traversal_driver = if global_style_data.style_thread_pool.is_none() || !element.is_root() { + let style_thread_pool = &*STYLE_THREAD_POOL; + let traversal_driver = if style_thread_pool.style_thread_pool.is_none() || !element.is_root() { TraversalDriver::Sequential } else { TraversalDriver::Parallel @@ -236,7 +237,7 @@ fn traverse_subtree(element: GeckoElement, let traversal = RecalcStyleOnly::new(shared_style_context, traversal_driver); if traversal_driver.is_parallel() { parallel::traverse_dom(&traversal, element, token, - global_style_data.style_thread_pool.as_ref().unwrap()); + style_thread_pool.style_thread_pool.as_ref().unwrap()); } else { sequential::traverse_dom(&traversal, element, token); } @@ -729,7 +730,7 @@ pub extern "C" fn Servo_Property_IsDiscreteAnimatable(property: nsCSSPropertyID) #[no_mangle] pub extern "C" fn Servo_StyleWorkerThreadCount() -> u32 { - GLOBAL_STYLE_DATA.num_threads as u32 + STYLE_THREAD_POOL.num_threads as u32 } #[no_mangle]