Skip to content

Conversation

@Loirooriol
Copy link
Collaborator

@Loirooriol Loirooriol commented Feb 9, 2026

Previously, Stylo was hard-coding the value for various preferences. Now Stylo will only define the default value for the preferences, but if the embedder sets a different value, the latter will be used instead.

For example, when not set otherwise, layout.threads used to default to 0 as any other i32 pref. However, this was a bad default, it meant that embedders like Blitz were running Stylo single-threaded. With this change we can make it default to -1, while still allowing Servo to set it to 3.

For consistent defaults, this replaces most style_config::get_bool() with static_prefs::pref!().

Servo PR: servo/servo#42491

Loirooriol added a commit to Loirooriol/servo that referenced this pull request Feb 9, 2026
…ences"

Bumps Stylo to servo/stylo#309

For consistency with Gecko, Stylo renames the `layout.threads` pref to
`layout.css.stylo-threads`. But it seems fine to keep `--layout_threads`
as the command argument.

stylo-prefs
@Loirooriol Loirooriol marked this pull request as ready for review February 10, 2026 00:16
@Loirooriol Loirooriol requested review from mrobinson and nicoburns and removed request for nicoburns February 10, 2026 00:16
Comment on lines +17 to +19
pub fn get_bool(&self, key: &str, default: bool) -> bool {
let prefs = self.bool_prefs.read().expect("RwLock is poisoned");
*prefs.get(key).unwrap_or(&false)
*prefs.get(key).unwrap_or(&default)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate that the API now must take the default value rather than being able to look up the default value itself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but static_prefs::pref!() gets the default automatically, and that's the API that we should use. E.g. Gecko doesn't have style_config::get_bool() at all.

Comment on lines +66 to +81
pub trait Getter {
fn get(key: &str, default: Self) -> Self;
}

impl Getter for bool {
fn get(key: &str, default: Self) -> Self {
get_bool(key, default)
}
}

impl Getter for i32 {
fn get(key: &str, default: Self) -> Self {
get_i32(key, default)
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are these used? I find it bizarre to add a get() method on i32 and bool. Maybe they can be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using this in

#[macro_export]
macro_rules! pref {
    ($string:tt) => {
        style_config::Getter::get($string, $crate::default_value!($string))
    };
}

The reason is that static_prefs::pref!() can access both booleans and numbers, so I needed a trait for the specialization.

Previously, Stylo was hard-coding the value for various preferences.
Now Stylo will only define the default value for the preferences, but if
the embedder sets a different value, the latter will be used instead.

For example, `layout.css.marker.restricted` should definitely default to
true (according to the spec), but Servo should be allowed to set it to
false e.g. for debugging purposes, or in specific tests.

For consistent defaults, this replaces most `style_config::get_bool()`
with `static_prefs::pref!()`. And the pref `layout.threads` gets renamed
to `layout.css.stylo-threads`, in order to share code with Gecko.

Signed-off-by: Oriol Brufau <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants