servo: Allow configuring style stack size#269
Conversation
| pub const STYLE_THREAD_STACK_SIZE_KB: usize = const { | ||
| let default_stack_size = 512; | ||
| if let Some(user_def_size) = option_env!("SERVO_STYLE_THREAD_STACK_SIZE_KB") { | ||
| if let Ok(user_def_size) = usize::from_str_radix(user_def_size, 10) { | ||
| user_def_size | ||
| } else { | ||
| panic!("SERVO_STYLE_THREAD_STACK_SIZE_KB must be a valid integer") | ||
| } | ||
| } else { | ||
| default_stack_size | ||
| } | ||
| }; |
There was a problem hiding this comment.
Would it be possible to make this a bit simpler and just increase the stack size when ASAN is enabled?
There was a problem hiding this comment.
Given servo/servo#40814 I would also like to do this for debug builds, if possible.
There was a problem hiding this comment.
I would prefer keeping it configurable too, since it allows embedders to adjust the stack size based on their needs.
The code is quite simple, just very verbose since we can't use any traits in const contexts, like and_then() or unwrap_or().
There was a problem hiding this comment.
@mrobinson Coming back to this, could we revive the discussion here on how to continue?
There was a problem hiding this comment.
Given servo/servo#40814 I would also like to do this for debug builds, if possible.
We have already increased the size here just for Servo due to our debug builds. I guess we could increase it again. If possible, it would be nice to have the build just work, no matter the build configuration, without having to set a magic environment variable. Also, what are the implications of exposing this in production builds?
Yet...why do we need a larger stack size than Gecko?
There was a problem hiding this comment.
Also, what are the implications of exposing this in production builds?
The environment variable is read at compile-time, so I don't see any issue there.
We have already increased the size here just for Servo due to our debug builds. I guess we could increase it again. If possible, it would be nice to have the build just work, no matter the build configuration, without having to set a magic environment variable.
As I understand, the whole point of this setting is to reduce the amount of memory the stylo threads use (since AFAIK the default is higher, I don't remember exactly but either 2 or 8 MB?). Increasing works, but it since release / production builds will require less memory due to optimizing, it would also be wasteful to just choose the highest option.
Yet...why do we need a larger stack size than Gecko?
I wonder if they perhaps always optimize stylo to a certain degree? (pure speculation)
There was a problem hiding this comment.
I would also like to do this for debug builds, if possible.
The difficult thing here is that we can't detect that. We can only check debug-assertions, but we also enable those in release mode in servo so it's not optimal.
But I guess I could live with a cfg(any(debug_assertions, asan)), although I'm not a huge fan, if thats preferred.
There was a problem hiding this comment.
The difficult thing here is that we can't detect that. We can only check debug-assertions, but we also enable those in release mode in servo so it's not optimal.
Thinking about it again, we need to ensure that we run servo CI with the smaller stack size, to prevent sudden crashes in production. And since we do want to enable debug_assertions in servos CI, those two goals kind of exclude themselves. So we are back to the embedder build system somehow needing to pass the information to stylo, which could either be a cfg, which would be a global rustflag, a feature flag "debug", or an environment variable like the current one.
There was a problem hiding this comment.
Apparently, Gecko's default debug build does include some Rust optimizations. Maybe we could do that same.
There was a problem hiding this comment.
Apparently, Gecko's default debug build does include some Rust optimizations. Maybe we could do that same.
I'm not opposed to that. IMHO it might make sense to optimize all non-workspace dependencies in servo with 1 or perhaps even 2. It would slow down clean debug builds, improve the performance of debug builds, and perhaps slightly regress the ability to debug issues in non-workspace dependencies with gdb. Seems like a trade-off we could make if we document it properly in the book.
Anyway, we would probably still need to increase the stack size for asan, although a global cfg option for that would be fine, since we anyway need to set rustflags for asan.
| let default_stack_size = 512; | ||
| if let Some(user_def_size) = option_env!("SERVO_STYLE_THREAD_STACK_SIZE_KB") { | ||
| if let Ok(user_def_size) = usize::from_str_radix(user_def_size, 10) { | ||
| user_def_size | ||
| } else { | ||
| panic!("SERVO_STYLE_THREAD_STACK_SIZE_KB must be a valid integer") | ||
| } | ||
| } else { | ||
| default_stack_size | ||
| } |
There was a problem hiding this comment.
I'm pretty sure I tried that, and its not available in const contexts sadly.
Edit: docs.rs confirms map on option is still unstable in const contexts.
When running Servo with ASAN we hit the stack limit. We can use compile-time parsing of environment variables, to allow the embedder to configure the style thread stack size.
7c96acc to
9f84f72
Compare
|
FYI, I can't merge to this repo, so someone else would need to click the merge button if everything is alright otherwise. |
Stylo servo/stylo#269 recently added the option to configure the stack size of the style threads. We increase the stack size for asan and debug builds. Signed-off-by: Jonathan Schwender <[email protected]>
When running Servo with ASAN we hit the stack limit. We can use compile-time parsing of environment variables, to allow the embedder to configure the style thread stack size. Fixes #223
When running Servo with ASAN we hit the stack limit. We can use compile-time parsing of environment variables, to allow the embedder to configure the style thread stack size. Fixes #223
There was a problem hiding this comment.
Instead of an env, wouldn't it be better to use style_config::get_i32() to get a pref that can be set from Servo? Like
stylo/style/global_style_data.rs
Line 159 in 3b46f3e
…-style-system-reviewers,dshin This imports servo/stylo#269 Differential Revision: https://phabricator.services.mozilla.com/D286391
…-style-system-reviewers,dshin This imports #269 Differential Revision: https://phabricator.services.mozilla.com/D286391
When running Servo with ASAN we hit the stack limit. We can use compile-time parsing of environment variables, to allow the embedder to configure the style thread stack size.
Fixes #223