зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #17492 - Separate thread pool from global state for Gecko (from glandium:master); r=emilio
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. Source-Repo: https://github.com/servo/servo Source-Revision: 3e4021ef1aaba9b58ffe57b74dc0012ddfcffe12 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : d34d4dcb8966328076e5e5c951c946e4d5b87ab4
This commit is contained in:
Родитель
0514137fed
Коммит
34ff8e795f
|
@ -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]
|
||||
|
|
Загрузка…
Ссылка в новой задаче