perf(parser): reduce code bloat from verify_modifiers monomorphization#23576
Merged
graphite-app[bot] merged 1 commit intoJun 18, 2026
Merged
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
Member
Author
Merge activity
|
#23576) ## What `verify_modifiers`'s inner cold `report<C, F>` is generic over the diagnostic-creating closure `F` and the parser `Config` `C`. With 3 concrete configs (`NoTokens`/`Tokens`/`Runtime`) and ~13 distinct call-site closures, it was monomorphized **~39 times**, and every copy dragged in the full `sort_unstable_by_key` + filter/collect machinery (quicksort, smallsort, merge, partition, …). This PR extracts the collect + sort into a **non-generic** helper `collect_disallowed`, so that heavy code — including the entire sort implementation — is compiled **once** rather than ~39 times. ## Why it's safe It's the cold, invalid-modifier error path: both functions are `#[cold]` + `#[inline(never)]`, so nothing here is on the hot path and there is no runtime cost. Pure refactor — behavior is unchanged. ## Impact `cargo llvm-lines --lib -p oxc_parser` (dev profile): | | Lines | Copies | |---|--:|--:| | before | 269,493 | 9,564 | | after | 197,808 | 7,817 | | **delta** | **−71,685 (−26.6%)** | **−1,747** | The sort helpers collapse from 39–78 copies each down to 1–2. This is reachable cold code that ships in the binary (not DCE'd), so it reduces both compile time and code size. Found via a `cargo llvm-lines` sweep of all published crates. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
e82cdc9 to
4058a6a
Compare
Boshen
added a commit
that referenced
this pull request
Jun 18, 2026
### 💥 BREAKING CHANGES - 7a76cd3 estree: [**BREAKING**] Make whether to include TS fields a runtime option (#23574) (overlookmotel) - e7b6b68 estree: [**BREAKING**] `ESTree` config use methods not consts (#23573) (overlookmotel) ### 🚀 Features - 556cc6d data_structures: Add `CodeBuffer::as_str` method (#23571) (overlookmotel) - 38c4b06 parser: Add friendly error for adjacent JSX elements (#23378) (sapphi-red) - 53509a8 minifier: Treeshake pure typed arrays and Set/Map array literals (#23469) (Dunqing) - 09762d9 minifier: Inline const value for read-only vars (#22593) (Dunqing) ### 🐛 Bug Fixes - 20375f9 react_compiler: Keep imports referenced only by a computed key (#23586) (Boshen) - 31bfd9b minifier: Keep Object introspection calls on a possible Proxy (#23483) (Dunqing) - 837a395 parser: Treat a line comment after ':' as leading, not trailing (#23515) (Dunqing) - e409fe0 minifier: Keep `new Map`/`WeakSet`/`WeakMap` with a string argument (#23470) (Dunqing) - ae02b4e ci/parser: Use `minimal` for vitest reporter (#23457) (camc314) ### ⚡ Performance - cf24329 mangler: Compile slot sort once instead of per CAPACITY (#23577) (Boshen) - 4058a6a parser: Reduce code bloat from verify_modifiers monomorphization (#23576) (Boshen) - 053b0c1 estree: Remove pointless `mem::take` (#23572) (overlookmotel) - dfb52b6 transformer: Pre-size statement vecs in TS enum & namespace lowering (#23516) (Yunfei He) - 970e09a minifier: Compute template-literal inline checks in a single pass (#23467) (Yunfei He) - 3170c0e semantic,mangler,minifier: Fix `Semantic::stats` node count and reuse stats in mangler builds (#23352) (Boshen) - d1fa6e0 minifier: Evaluate ternary branches once in minimize_conditional_expression (#23479) (Yunfei He) - 3fa8051 transformer: Pre-size JSX props vec to attribute count (#23466) (Yunfei He) - 488b382 react_compiler: Borrow binding names in prefilter instead of allocating (#23471) (Yunfei He) - bcb3894 minifier: Incremental scoping refresh, delete LiveUsageCollector (#23197) (Dunqing) ### 📚 Documentation - f68641e data_structures: Improve docs on safety contract (#23575) (overlookmotel) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
camc314
pushed a commit
that referenced
this pull request
Jul 3, 2026
#23576) ## What `verify_modifiers`'s inner cold `report<C, F>` is generic over the diagnostic-creating closure `F` and the parser `Config` `C`. With 3 concrete configs (`NoTokens`/`Tokens`/`Runtime`) and ~13 distinct call-site closures, it was monomorphized **~39 times**, and every copy dragged in the full `sort_unstable_by_key` + filter/collect machinery (quicksort, smallsort, merge, partition, …). This PR extracts the collect + sort into a **non-generic** helper `collect_disallowed`, so that heavy code — including the entire sort implementation — is compiled **once** rather than ~39 times. ## Why it's safe It's the cold, invalid-modifier error path: both functions are `#[cold]` + `#[inline(never)]`, so nothing here is on the hot path and there is no runtime cost. Pure refactor — behavior is unchanged. ## Impact `cargo llvm-lines --lib -p oxc_parser` (dev profile): | | Lines | Copies | |---|--:|--:| | before | 269,493 | 9,564 | | after | 197,808 | 7,817 | | **delta** | **−71,685 (−26.6%)** | **−1,747** | The sort helpers collapse from 39–78 copies each down to 1–2. This is reachable cold code that ships in the binary (not DCE'd), so it reduces both compile time and code size. Found via a `cargo llvm-lines` sweep of all published crates. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
camc314
pushed a commit
that referenced
this pull request
Jul 3, 2026
### 💥 BREAKING CHANGES - 7a76cd3 estree: [**BREAKING**] Make whether to include TS fields a runtime option (#23574) (overlookmotel) - e7b6b68 estree: [**BREAKING**] `ESTree` config use methods not consts (#23573) (overlookmotel) ### 🚀 Features - 556cc6d data_structures: Add `CodeBuffer::as_str` method (#23571) (overlookmotel) - 38c4b06 parser: Add friendly error for adjacent JSX elements (#23378) (sapphi-red) - 53509a8 minifier: Treeshake pure typed arrays and Set/Map array literals (#23469) (Dunqing) - 09762d9 minifier: Inline const value for read-only vars (#22593) (Dunqing) ### 🐛 Bug Fixes - 20375f9 react_compiler: Keep imports referenced only by a computed key (#23586) (Boshen) - 31bfd9b minifier: Keep Object introspection calls on a possible Proxy (#23483) (Dunqing) - 837a395 parser: Treat a line comment after ':' as leading, not trailing (#23515) (Dunqing) - e409fe0 minifier: Keep `new Map`/`WeakSet`/`WeakMap` with a string argument (#23470) (Dunqing) - ae02b4e ci/parser: Use `minimal` for vitest reporter (#23457) (camc314) ### ⚡ Performance - cf24329 mangler: Compile slot sort once instead of per CAPACITY (#23577) (Boshen) - 4058a6a parser: Reduce code bloat from verify_modifiers monomorphization (#23576) (Boshen) - 053b0c1 estree: Remove pointless `mem::take` (#23572) (overlookmotel) - dfb52b6 transformer: Pre-size statement vecs in TS enum & namespace lowering (#23516) (Yunfei He) - 970e09a minifier: Compute template-literal inline checks in a single pass (#23467) (Yunfei He) - 3170c0e semantic,mangler,minifier: Fix `Semantic::stats` node count and reuse stats in mangler builds (#23352) (Boshen) - d1fa6e0 minifier: Evaluate ternary branches once in minimize_conditional_expression (#23479) (Yunfei He) - 3fa8051 transformer: Pre-size JSX props vec to attribute count (#23466) (Yunfei He) - 488b382 react_compiler: Borrow binding names in prefilter instead of allocating (#23471) (Yunfei He) - bcb3894 minifier: Incremental scoping refresh, delete LiveUsageCollector (#23197) (Dunqing) ### 📚 Documentation - f68641e data_structures: Improve docs on safety contract (#23575) (overlookmotel) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
verify_modifiers's inner coldreport<C, F>is generic over the diagnostic-creating closureFand the parserConfigC. With 3 concrete configs (NoTokens/Tokens/Runtime) and ~13 distinct call-site closures, it was monomorphized ~39 times, and every copy dragged in the fullsort_unstable_by_key+ filter/collect machinery (quicksort, smallsort, merge, partition, …).This PR extracts the collect + sort into a non-generic helper
collect_disallowed, so that heavy code — including the entire sort implementation — is compiled once rather than ~39 times.Why it's safe
It's the cold, invalid-modifier error path: both functions are
#[cold]+#[inline(never)], so nothing here is on the hot path and there is no runtime cost. Pure refactor — behavior is unchanged.Impact
cargo llvm-lines --lib -p oxc_parser(dev profile):The sort helpers collapse from 39–78 copies each down to 1–2. This is reachable cold code that ships in the binary (not DCE'd), so it reduces both compile time and code size.
Found via a
cargo llvm-linessweep of all published crates.🤖 Generated with Claude Code