mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Make stylo thread pool size configurable via pref rather than just env
Remove a variety of code which we don't use to change the pool size. We can just use the pref as needed in the future. Differential Revision: https://phabricator.services.mozilla.com/D178575
This commit is contained in:
parent
3a51e530d2
commit
10f8eb4239
1 changed files with 32 additions and 48 deletions
|
@ -14,9 +14,7 @@ use crate::thread_state;
|
||||||
use gecko_profiler;
|
use gecko_profiler;
|
||||||
use parking_lot::{Mutex, RwLock, RwLockReadGuard};
|
use parking_lot::{Mutex, RwLock, RwLockReadGuard};
|
||||||
use rayon;
|
use rayon;
|
||||||
use std::env;
|
use std::{io, thread};
|
||||||
use std::io;
|
|
||||||
use std::thread;
|
|
||||||
|
|
||||||
/// Global style data
|
/// Global style data
|
||||||
pub struct GlobalStyleData {
|
pub struct GlobalStyleData {
|
||||||
|
@ -114,50 +112,40 @@ impl StyleThreadPool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
|
fn stylo_threads_pref() -> i32 {
|
||||||
|
pref!(layout.threads)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
fn stylo_threads_pref() -> i32 {
|
||||||
|
static_prefs::pref!("layout.css.stylo-threads")
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
/// Global thread pool
|
/// Global thread pool
|
||||||
pub static ref STYLE_THREAD_POOL: std::sync::Mutex<StyleThreadPool> = {
|
pub static ref STYLE_THREAD_POOL: std::sync::Mutex<StyleThreadPool> = {
|
||||||
let stylo_threads = env::var("STYLO_THREADS")
|
// We always set this pref on startup, before layout or script have had a chance of
|
||||||
.map(|s| s.parse::<usize>().expect("invalid STYLO_THREADS value"));
|
// accessing (and thus creating) the thread-pool.
|
||||||
let mut num_threads = match stylo_threads {
|
let threads_pref: i32 = stylo_threads_pref();
|
||||||
Ok(num) => num,
|
|
||||||
#[cfg(feature = "servo")]
|
let num_threads = if threads_pref >= 0 {
|
||||||
_ => {
|
threads_pref as usize
|
||||||
use servo_config::pref;
|
} else {
|
||||||
// We always set this pref on startup, before layout or script
|
|
||||||
// have had a chance of accessing (and thus creating) the
|
|
||||||
// thread-pool.
|
|
||||||
pref!(layout.threads) 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 num_cpus;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
cmp::min(cmp::max(num_cpus::get() * 3 / 4, 1), 6)
|
// 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).
|
||||||
|
let threads = cmp::min(cmp::max(num_cpus::get() * 3 / 4, 1), 6);
|
||||||
|
// There's no point in creating a thread pool if there's one thread.
|
||||||
|
if threads == 1 { 0 } else { threads }
|
||||||
};
|
};
|
||||||
|
|
||||||
// If num_threads is one, there's no point in creating a thread pool, so
|
let (pool, num_threads) = if num_threads < 1 {
|
||||||
// force it to zero.
|
(None, None)
|
||||||
//
|
|
||||||
// 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::<usize>().expect("invalid FORCE_STYLO_THREAD_POOL value") == 1);
|
|
||||||
if !force_pool {
|
|
||||||
num_threads = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let pool = if num_threads < 1 {
|
|
||||||
None
|
|
||||||
} else {
|
} else {
|
||||||
let workers = rayon::ThreadPoolBuilder::new()
|
let workers = rayon::ThreadPoolBuilder::new()
|
||||||
.spawn_handler(thread_spawn)
|
.spawn_handler(thread_spawn)
|
||||||
|
@ -167,15 +155,11 @@ lazy_static! {
|
||||||
.exit_handler(thread_shutdown)
|
.exit_handler(thread_shutdown)
|
||||||
.stack_size(STYLE_THREAD_STACK_SIZE_KB * 1024)
|
.stack_size(STYLE_THREAD_STACK_SIZE_KB * 1024)
|
||||||
.build();
|
.build();
|
||||||
workers.ok()
|
(workers.ok(), Some(num_threads))
|
||||||
};
|
};
|
||||||
|
|
||||||
std::sync::Mutex::new(StyleThreadPool {
|
std::sync::Mutex::new(StyleThreadPool {
|
||||||
num_threads: if num_threads > 0 {
|
num_threads,
|
||||||
Some(num_threads)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
style_thread_pool: RwLock::new(pool),
|
style_thread_pool: RwLock::new(pool),
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue