Skip to content

Shrink ParserState - #457

Merged
emilio merged 2 commits into
mainfrom
shrink-parserstate
Oct 8, 2026
Merged

emilio merged 2 commits into
mainfrom
shrink-parserstate

Conversation

@emilio

@emilio emilio commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

See the two commits. This improves state restoration performance which is pretty hot.

@emilio

emilio commented Sep 20, 2026

Copy link
Copy Markdown
Member Author

A less ugly alternative for the last commit might be to just reduce the line count to a u16... I'll test that, that gives us some padding for more state later too...

Comment thread src/parser.rs
/// Current line number shifted by `Self::BLOCK_TYPE_BITS`, with the low 2 bits holding the
/// `BlockType` discriminant of the block the last returned token opened (if any).
line_number_and_block_type: u32,
}

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.

Further microbenchmarking showed that most of the win (on those microbenchmarks at least) comes from making the Clone impl a memcpy rather than a per-field copy (why does rustc not collapse everything onto a memcpy without derive(Copy), I don't know)...

Making it smaller is a smaller win on top, so maybe we should just take this anyway, since I think it's not too complicated...

@emilio
emilio marked this pull request as ready for review September 21, 2026 17:13
@emilio emilio changed the title WIP: Shrink ParserState Shrink ParserState Sep 21, 2026
lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Oct 7, 2026
…ystem-reviewers,supply-chain-reviewers,dshin

This needs a tweak in servo/ for a behavior change on how arbitrary
substitution functions are dealt with, see the discussion in
servo/rust-cssparser#456.

I wanted to do this once
servo/rust-cssparser#457 was reviewed but that's
taking a while and I need to work on other bugfixes too, so landing the
update to main first.

Differential Revision: https://phabricator.services.mozilla.com/D331712
github-actions Bot pushed a commit to DioxusLabs/stylo that referenced this pull request Oct 8, 2026
…ystem-reviewers,supply-chain-reviewers,dshin

This needs a tweak in servo/ for a behavior change on how arbitrary
substitution functions are dealt with, see the discussion in
servo/rust-cssparser#456.

I wanted to do this once
servo/rust-cssparser#457 was reviewed but that's
taking a while and I need to work on other bugfixes too, so landing the
update to main first.

Differential Revision: https://phabricator.services.mozilla.com/D331712

@nicoburns nicoburns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Definitely in the territory of "should only do this in a hot loop". But it sounds like that's the case here.

Comment thread src/parser.rs Outdated
We already truncate column numbers to u32, so this gives the same answer
it would otherwise give, and saves some storage (not in this patch
because ParserState is still 24 bytes, but we can improve on that in a
bit).
@emilio
emilio force-pushed the shrink-parserstate branch from f3ad62b to e48c2c3 Compare October 8, 2026 16:55
…k type.

The line number range gets a bit smaller, but it pays off by making
state restoration faster, which is a lot hotter.
@emilio
emilio force-pushed the shrink-parserstate branch from e48c2c3 to 29b5987 Compare October 8, 2026 16:58
@emilio
emilio enabled auto-merge October 8, 2026 16:59
@emilio
emilio added this pull request to the merge queue Oct 8, 2026
Merged via the queue into main with commit 9f3cedd Oct 8, 2026
14 checks passed
@emilio
emilio deleted the shrink-parserstate branch October 8, 2026 17:08
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.

2 participants