Skip to content

Truly independent web browser

LibWeb: Ask for the number of style threads once

Andreas Kling9f0d75fd7d99
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs
index 34eacb3e058..52d5f10b43a 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs
@@ -59,7 +59,11 @@ const DEFAULT_MAX_THREAD_COUNT: usize = 8;
/// How many threads the traversal runs on where none are asked for: three of every four logical
/// processors, leaving the others to the main thread and the rest of the process, and at least one.
pub(super) fn thread_count() -> usize {
- std::thread::available_parallelism().map_or(1, |count| (count.get() * 3 / 4).clamp(1, DEFAULT_MAX_THREAD_COUNT))
+ // NB: Each pass asks, and the answer takes system calls and reading files of the control groups.
+ static THREAD_COUNT: std::sync::OnceLock<usize> = std::sync::OnceLock::new();
+ *THREAD_COUNT.get_or_init(|| {
+ std::thread::available_parallelism().map_or(1, |count| (count.get() * 3 / 4).clamp(1, DEFAULT_MAX_THREAD_COUNT))
+ })
}
/// How many elements a task hands to another at once.
diff --git a/Meta/Linters/check_rust_process_wide_state.py b/Meta/Linters/check_rust_process_wide_state.py
index e58bafce24e..0086552b2c1 100755
--- a/Meta/Linters/check_rust_process_wide_state.py
+++ b/Meta/Linters/check_rust_process_wide_state.py
@@ -135,6 +135,7 @@ RENDER_STATE_ALLOWED = {
"css/parser/stylesheet_cache.rs:HASHER",
"css/parser/stylesheet_cache.rs:KEYS",
"css/property_metadata.rs:SHORTHAND_LEAVES",
+ "css/style/pipeline/traversal.rs:THREAD_COUNT",
"css/style_compute.rs:DIRECT",
"css/style_compute.rs:FONT_ORDER",
"css/style_compute.rs:FONT_PHASES",