Skip to content

Shrink ParserState - #457

Open
emilio wants to merge 2 commits into
mainfrom
shrink-parserstate
Open

emilio wants to merge 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...

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).
…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 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

This branch has not been deployed

No deployments
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.

1 participant