mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #17492 - glandium:master, r=emilio
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. <!-- 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/17492) <!-- Reviewable:end -->
This commit is contained in:
commit
3e4021ef1a
2 changed files with 22 additions and 15 deletions
|
@ -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<rayon::ThreadPool>,
|
||||
|
||||
/// 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<rayon::ThreadPool>,
|
||||
}
|
||||
|
||||
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::<usize>().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(),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue