Skip to content

Allow some AttrValue variants to be serialized lazily#365

Merged
mrobinson merged 1 commit into
servo:mainfrom
mrobinson:enable-lazy-serialization
May 19, 2026
Merged

Allow some AttrValue variants to be serialized lazily#365
mrobinson merged 1 commit into
servo:mainfrom
mrobinson:enable-lazy-serialization

Conversation

@mrobinson
Copy link
Copy Markdown
Member

@mrobinson mrobinson commented May 14, 2026

This allows some AttrValue variants, the ones that are easily
serializable and are sometimes set without existing serializations, to
be lazily serialized. The goal here is to allow storing these values,
but only serializing when necessary.

Servo PR: servo/servo#44931

@nicoburns
Copy link
Copy Markdown
Collaborator

nicoburns commented May 14, 2026

What's the rationale for not also implementing this for LengthPercentage, Color, and Dimension?

@mrobinson
Copy link
Copy Markdown
Member Author

What's the rationale for not also implementing this for LengthPercentage, Color, and Dimension?

Two reasons:

  1. Currently they are all created via parsing a serialization, so we already have a serialization when they are created (which should be preserved).
  2. There are no pre-existing serialization methods for these types, so they would have to be written -- but would be dead code due to number 1.

@mrobinson mrobinson force-pushed the enable-lazy-serialization branch from a1679eb to 616a2ed Compare May 15, 2026 15:51
Comment thread malloc_size_of/lib.rs Outdated

impl<T: MallocSizeOf> MallocSizeOf for std::sync::OnceLock<T> {
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
self.get().size_of(ops)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this might call <Option<&T>>::size_of which is always zero because of the &, but it should optionally call T::size_of which may not be zero

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've addressed this in the latest push.

@mrobinson mrobinson force-pushed the enable-lazy-serialization branch from 616a2ed to 0e116a4 Compare May 18, 2026 08:55
This allows some `AttrValue` variants, the ones that are easily
serializable and are sometimes set without existing serializations, to
be lazily serialized. The goal here is to allow storing these values,
but only serializing when necessary.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
@mrobinson mrobinson force-pushed the enable-lazy-serialization branch from 0e116a4 to acf239d Compare May 18, 2026 14:22
@mrobinson mrobinson added this pull request to the merge queue May 19, 2026
Merged via the queue into servo:main with commit d2b3101 May 19, 2026
5 checks passed
@mrobinson mrobinson deleted the enable-lazy-serialization branch May 19, 2026 07:12
pull Bot pushed a commit to A-Archives-and-Forks/servo that referenced this pull request May 19, 2026
…ervo#44931)

This change allows creating an `AttrValue` without a serialization.
This is *particularly* important when setting the `style` attribute on
elements, as many pages set the `style` attribute but never read it.
Eagerly serializing the attribute in these cases is pure overhead. This
kind of thing shows up prominently in profiles.

This change starts adapting Servo to Stylo's support for lazy
serialization of some attributes. In addition, some eager serialization
during attribute mutations is avoided as well.

Followup changes will:

 - Make it more obvious when a potentially expensive serialization of an
   attribute is performed.
 - Make it clear when an attribute is constructed with a pre-existing
   serialization.

Tthese changes lead to a 25% speedup when running

`tests/blink_perf_tests/perf_tests/layout/flexbox-deeply-nested-column-flow.html`
on my system.

Stylo PR: servo/stylo#365

Testing: This should not change observable behavior and unfortunately we
do not
have automated performance tests.
Fixes: servo#17399.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
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