Commit 43c710b2 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1834144 - Make stylo thread pool size configurable via pref rather than...

Bug 1834144 - Make stylo thread pool size configurable via pref rather than just env. r=smaug,perftest-reviewers,jgraham,afinder

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
parent fc4076d8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1684,8 +1684,8 @@ bool nsRefreshDriver::CanDoExtraTick() {
}

void nsRefreshDriver::EnsureTimerStarted(EnsureTimerStartedFlags aFlags) {
  // FIXME: Bug 1346065: We should also assert the case where we have
  // STYLO_THREADS=1.
  // FIXME: Bug 1346065: We should also assert the case where we have no
  // stylo-threads.
  MOZ_ASSERT(!ServoStyleSet::IsInServoTraversal() || NS_IsMainThread(),
             "EnsureTimerStarted should be called only when we are not "
             "in servo traversal or on the main-thread");
+10 −0
Original line number Diff line number Diff line
@@ -8945,6 +8945,16 @@
  mirror: always
  rust: true

# Stylo thread-pool size.
# Negative means auto, 0 disables the thread-pool (main-thread styling), other
# numbers override as specified.
# Note that 1 still creates a thread-pool of one thread!
- name: layout.css.stylo-threads
  type: int32_t
  value: -1
  mirror: once
  rust: true

# Are counters for implemented CSS properties enabled?
- name: layout.css.use-counters.enabled
  type: bool
+32 −48
Original line number Diff line number Diff line
@@ -13,9 +13,7 @@ use crate::thread_state;
use gecko_profiler;
use parking_lot::{Mutex, RwLock, RwLockReadGuard};
use rayon;
use std::env;
use std::io;
use std::thread;
use std::{io, thread};

/// Global style data
pub struct GlobalStyleData {
@@ -113,50 +111,40 @@ impl StyleThreadPool {
    }
}

lazy_static! {
    /// 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 {
            Ok(num) => num,
#[cfg(feature = "servo")]
            _ => {
                use servo_config::pref;
                // 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
fn stylo_threads_pref() -> i32 {
    pref!(layout.threads)
}

#[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)
fn stylo_threads_pref() -> i32 {
    static_prefs::pref!("layout.css.stylo-threads")
}
        };

        // If num_threads is one, there's no point in creating a thread pool, so
        // force it to zero.
lazy_static! {
    /// Global thread pool
    pub static ref STYLE_THREAD_POOL: StyleThreadPool = {
        // We always set this pref on startup, before layout or script have had a chance of
        // accessing (and thus creating) the thread-pool.
        let threads_pref: i32 = stylo_threads_pref();

        let num_threads = if threads_pref >= 0 {
            threads_pref as usize
        } else {
            use num_cpus;
            use std::cmp;
            // 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.
            //
        // 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;
            }
        }
            // 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 }
        };

        let pool = if num_threads < 1 {
            None
        let (pool, num_threads) = if num_threads < 1 {
            (None, None)
        } else {
            let workers = rayon::ThreadPoolBuilder::new()
                .spawn_handler(thread_spawn)
@@ -166,15 +154,11 @@ lazy_static! {
                .exit_handler(thread_shutdown)
                .stack_size(STYLE_THREAD_STACK_SIZE_KB * 1024)
                .build();
            workers.ok()
            (workers.ok(), Some(num_threads))
        };

        StyleThreadPool {
            num_threads: if num_threads > 0 {
                Some(num_threads)
            } else {
                None
            },
            num_threads,
            style_thread_pool: RwLock::new(pool),
        }
    };
+0 −10
Original line number Diff line number Diff line
@@ -114,16 +114,6 @@ def create_suite(
    if extra_opts:
        opts.extend(extra_opts)

    # The stylo attributes override each other.
    stylo_opt = None
    if "STYLO_FORCE_ENABLED" in os.environ and os.environ["STYLO_FORCE_ENABLED"]:
        stylo_opt = "stylo"
    if "STYLO_THREADS" in os.environ and os.environ["STYLO_THREADS"] == "1":
        stylo_opt = "stylo-sequential"

    if stylo_opt:
        opts.append(stylo_opt)

    if "DMD" in os.environ and os.environ["DMD"]:
        opts.append("dmd")

+0 −5
Original line number Diff line number Diff line
@@ -49,11 +49,6 @@ def run_awsy(command_context, tests, binary=None, **kwargs):
        kwargs["perTabPause"] = 1
        kwargs["settleWaitTime"] = 1

    if "single_stylo_traversal" in kwargs and kwargs["single_stylo_traversal"]:
        os.environ["STYLO_THREADS"] = "1"
    else:
        os.environ["STYLO_THREADS"] = "4"

    runtime_testvars = {}
    for arg in (
        "webRootDir",
Loading