script/mach: Increase stack size of ScriptThread/StyleThread to 8MiB to match recursion depth of other browsers#43888
Conversation
ScriptThread to 8MiB to match recursion depth of other browsers
|
🔨 Triggering try run (#23935508368) for Linux (WPT) |
|
Test results for linux-wpt from try job (#23935508368): Flaky unexpected result (33)
Stable unexpected results that are known to be intermittent (16)
|
|
✨ Try run (#23935508368) succeeded. |
TimvdLippe
left a comment
There was a problem hiding this comment.
Should we add a crash test for this to our Servo only tests?
Sounds good to me. |
Ehh. Got into trouble. When running below directly as file, it is fine with this PR. <!doctype html>
<div id="X"></div>
<script>
let p = X
for (let i=0;i<1551;i++) {
let x = document.createElement('div')
let r = x.attachShadow({
mode:'open', clonable: true
})
p.appendChild(x)
p = r
}
p.innerHTML = `Hello!`
</script>I don't know why StyleThread overflow only triggered by wpt test. |
This comment was marked as outdated.
This comment was marked as outdated.
It seems because, wpt test load Directly refreshing or navigating to the target page can also trigger the StyleThread overflow :/ navigate.mp4refresh.mp4 |
|
FYI, you can increase the stack size of the style threads via |
It seems the default is 2048 based on output in target/release/deps/style-{hash}.d That's kind strange: it seems we only set the variable for debug build and ASAN builds.. servo/python/servo/command_base.py Lines 420 to 423 in 0b6b973 How come we also get 2048 for release? |
Filed #43927 |
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
ScriptThread to 8MiB to match recursion depth of other browsersScriptThread/StyleThread to 8MiB to match recursion depth of other browsers
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
ScriptThread/StyleThread to 8MiB to match recursion depth of other browsersScriptThread/StyleThread to 8MiB to match recursion depth of other browsers
| env["TARGET_CFLAGS"] += " -fsanitize=address" | ||
| env["TARGET_CXXFLAGS"] += " -fsanitize=address" | ||
|
|
||
| # Set servo style thread stack size to 8 MB for ASAN builds since the stack usage is higher. |
There was a problem hiding this comment.
We use 8 for all builds unconditionally.
There was a problem hiding this comment.
Hmm, I believe we might want to investigate that. If Firefox can work fine with 256K stack size for the style threads, then there might be a deeper issue on our side if we need to increase that all the way up to 8MB
TL;DR: We increase stack size of
ScriptThreadto 8MiB, and set Stylo stack size environment varto 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:
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:
For Chromium, the visual studio dumpbin shows the stack size :
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