mirror of
https://github.com/servo/servo
synced 2026-04-25 17:15:48 +02:00
script/mach: Increase stack size of ScriptThread/StyleThread to 8MiB to match recursion depth of other browsers (#43888)
TL;DR: We increase stack size of `ScriptThread` to 8MiB, and set Stylo stack size environment var to 8 MiB for all builds. This only reserves virtual memory space which is basically unlimited for 64-bit machine, matches the recursion depth of Chromium for the example, which also uses 8MiB. Stylo stack increase is necessary to prevent overflow when refreshing/navigating to the example, probably because initial load restyle incrementally but not refresh. Testing: Added a Servo-specific test. --- For example in #43845, we get stack overflow when we got more than 394 nested shadow roots. For Chromium, it happens for more than 1631: <img width="290" height="127" alt="image" src="https://github.com/user-attachments/assets/b3d75627-4e80-4586-9b85-4b58d8a0cd33" /> For Firefox, it overflows for more than 1052. Initially I thought we didn't implement this optimally, and have unnecessary recursion depth. But the real reason is explained in Rust std: > The default stack size is platform-dependent and subject to change. Currently, it is 2 MiB on all Tier-1 platforms. For Chromium, the visual studio dumpbin shows the stack size : ``` Dump of file C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe OPTIONAL HEADER VALUES 800000 size of stack reserve ``` This is hex value, which is $8*16^5$, exactly 8MiB. After we make the same change in Servo, we are fine at 1601 and overflows at 1602. This matches Chromium behaviour, defeating firefox, and should not create much overhead, as this only reserves virtual memory space: I tried to increase the value to 512MiB, but task manager still says 73MB RAM used, and we won't crash even with 10000 nested shadow roots. But that is just for more evidence and uncalled for. Fixes: #43845 --------- Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
@@ -468,6 +468,7 @@ impl ScriptThreadFactory for ScriptThread {
|
||||
let script_thread_id = state.id;
|
||||
thread::Builder::new()
|
||||
.name(format!("Script#{script_thread_id}"))
|
||||
.stack_size(8 * 1024 * 1024) // 8 MiB stack to be consistent with other browsers.
|
||||
.spawn(move || {
|
||||
thread_state::initialize(ThreadState::SCRIPT);
|
||||
PipelineNamespace::install(state.pipeline_namespace_id);
|
||||
|
||||
Reference in New Issue
Block a user