mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
* Add prefs to limit threadpool sizes Add preferences to control the size of threadpools, so that we can easily reduce the amount of runtime threads and test which pools benefit from more threads. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> * Add pref for Webrender threadpool Add a preference to limit the size of the webrender threadpool. Note: WebRender by default calls hooks which register the threads with a profiler instance that the embedder can register with webrender. Servo currently doesn't register such a profiler with webrender, but in the future we might also want to profile the webrender threadpool. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> --------- Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
32 lines
1.2 KiB
Rust
32 lines
1.2 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
use std::cmp::Ord;
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
use std::sync::{LazyLock, Mutex};
|
|
use std::thread;
|
|
|
|
use tokio::runtime::{Builder, Runtime};
|
|
|
|
pub static HANDLE: LazyLock<Mutex<Option<Runtime>>> = LazyLock::new(|| {
|
|
Mutex::new(Some(
|
|
Builder::new_multi_thread()
|
|
.thread_name_fn(|| {
|
|
static ATOMIC_ID: AtomicUsize = AtomicUsize::new(0);
|
|
let id = ATOMIC_ID.fetch_add(1, Ordering::Relaxed);
|
|
format!("tokio-runtime-{}", id)
|
|
})
|
|
.worker_threads(
|
|
thread::available_parallelism()
|
|
.map(|i| i.get())
|
|
.unwrap_or(servo_config::pref!(threadpools.fallback_worker_num) as usize)
|
|
.min(
|
|
servo_config::pref!(threadpools.async_runtime_workers.max).max(1) as usize,
|
|
),
|
|
)
|
|
.enable_io()
|
|
.enable_time()
|
|
.build()
|
|
.unwrap(),
|
|
))
|
|
});
|