mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Auto merge of #22487 - emilio:single-layout-thread-pool, r=jdm
style: Make Servo use a single thread-pool for layout-related tasks per process. Instead of per-document. This also allows to reuse this thread-pool if needed for other stuff, like parallel CSS parsing (#22478), and to share more code with Gecko, which is always nice. <!-- 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/22487) <!-- Reviewable:end -->
This commit is contained in:
commit
b5a10e9c96
12 changed files with 56 additions and 77 deletions
|
@ -16,8 +16,7 @@ path = "lib.rs"
|
|||
doctest = false
|
||||
|
||||
[features]
|
||||
gecko = ["num_cpus",
|
||||
"style_traits/gecko", "fallible/known_system_malloc"]
|
||||
gecko = ["style_traits/gecko", "fallible/known_system_malloc"]
|
||||
use_bindgen = ["bindgen", "regex", "toml"]
|
||||
servo = ["serde", "style_traits/servo", "servo_atoms", "servo_config", "html5ever",
|
||||
"cssparser/serde", "encoding_rs", "malloc_size_of/servo", "arrayvec/use_union",
|
||||
|
@ -47,7 +46,7 @@ log = "0.4"
|
|||
malloc_size_of = { path = "../malloc_size_of" }
|
||||
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
|
||||
matches = "0.1"
|
||||
num_cpus = {version = "1.1.0", optional = true}
|
||||
num_cpus = {version = "1.1.0"}
|
||||
num-integer = "0.1"
|
||||
num-traits = "0.2"
|
||||
num-derive = "0.2"
|
||||
|
|
|
@ -10,7 +10,6 @@ mod non_ts_pseudo_class_list;
|
|||
pub mod arc_types;
|
||||
pub mod conversions;
|
||||
pub mod data;
|
||||
pub mod global_style_data;
|
||||
pub mod media_features;
|
||||
pub mod media_queries;
|
||||
pub mod pseudo_element;
|
||||
|
|
|
@ -5,15 +5,13 @@
|
|||
//! Global style data
|
||||
|
||||
use crate::context::StyleSystemOptions;
|
||||
#[cfg(feature = "gecko")]
|
||||
use crate::gecko_bindings::bindings;
|
||||
use crate::parallel::STYLE_THREAD_STACK_SIZE_KB;
|
||||
use crate::shared_lock::SharedRwLock;
|
||||
use crate::thread_state;
|
||||
use num_cpus;
|
||||
use rayon;
|
||||
use std::cmp;
|
||||
use std::env;
|
||||
use std::ffi::CString;
|
||||
|
||||
/// Global style data
|
||||
pub struct GlobalStyleData {
|
||||
|
@ -37,20 +35,22 @@ fn thread_name(index: usize) -> String {
|
|||
format!("StyleThread#{}", index)
|
||||
}
|
||||
|
||||
fn thread_startup(index: usize) {
|
||||
fn thread_startup(_index: usize) {
|
||||
thread_state::initialize_layout_worker_thread();
|
||||
#[cfg(feature = "gecko")]
|
||||
unsafe {
|
||||
use std::ffi::CString;
|
||||
|
||||
bindings::Gecko_SetJemallocThreadLocalArena(true);
|
||||
}
|
||||
let name = thread_name(index);
|
||||
let name = CString::new(name).unwrap();
|
||||
unsafe {
|
||||
let name = thread_name(_index);
|
||||
let name = CString::new(name).unwrap();
|
||||
// Gecko_RegisterProfilerThread copies the passed name here.
|
||||
bindings::Gecko_RegisterProfilerThread(name.as_ptr());
|
||||
}
|
||||
}
|
||||
|
||||
fn thread_shutdown(_: usize) {
|
||||
#[cfg(feature = "gecko")]
|
||||
unsafe {
|
||||
bindings::Gecko_UnregisterProfilerThread();
|
||||
bindings::Gecko_SetJemallocThreadLocalArena(false);
|
||||
|
@ -64,12 +64,26 @@ lazy_static! {
|
|||
.map(|s| s.parse::<usize>().expect("invalid STYLO_THREADS value"));
|
||||
let mut num_threads = match stylo_threads {
|
||||
Ok(num) => num,
|
||||
// The default heuristic is num_virtual_cores * .75. This gives us
|
||||
// three threads on a hyper-threaded dual core, and six threads on
|
||||
// a hyper-threaded quad core. The performance benefit of additional
|
||||
// threads seems to level off at around six, so we cap it there on
|
||||
// many-core machines (see bug 1431285 comment 14).
|
||||
_ => cmp::min(cmp::max(num_cpus::get() * 3 / 4, 1), 6),
|
||||
#[cfg(feature = "servo")]
|
||||
_ => {
|
||||
// We always set this pref on startup, before layout or script
|
||||
// have had a chance of accessing (and thus creating) the
|
||||
// thread-pool.
|
||||
use servo_config::prefs::PREFS;
|
||||
PREFS.get("layout.threads").as_u64().unwrap() as usize
|
||||
}
|
||||
#[cfg(feature = "gecko")]
|
||||
_ => {
|
||||
// The default heuristic is num_virtual_cores * .75. This gives
|
||||
// us three threads on a hyper-threaded dual core, and six
|
||||
// threads on a hyper-threaded quad core. The performance
|
||||
// benefit of additional threads seems to level off at around
|
||||
// six, so we cap it there on many-core machines
|
||||
// (see bug 1431285 comment 14).
|
||||
use num_cpus;
|
||||
use std::cmp;
|
||||
cmp::min(cmp::max(num_cpus::get() * 3 / 4, 1), 6)
|
||||
}
|
||||
};
|
||||
|
||||
// If num_threads is one, there's no point in creating a thread pool, so
|
|
@ -133,6 +133,7 @@ pub mod font_metrics;
|
|||
#[cfg(feature = "gecko")]
|
||||
#[allow(unsafe_code)]
|
||||
pub mod gecko_bindings;
|
||||
pub mod global_style_data;
|
||||
pub mod hash;
|
||||
pub mod invalidation;
|
||||
#[allow(missing_docs)] // TODO.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue