refactor(parser): use cold_path for pure branch-layout hints#24380
Merged
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
overlookmotel
approved these changes
Jul 12, 2026
Member
Merge activity
|
Rust 1.95 stabilized [`std::hint::cold_path`](https://doc.rust-lang.org/std/hint/fn.cold_path.html), re-exported via `oxc_data_structures::branch_hints` in #24368. This replaces the `cold_branch` closure trampoline with `cold_path()` at the **14 call sites where the hint only guides branch layout** — straight-line code instead of closure ceremony. The other **10 sites keep `cold_branch` deliberately**: they build diagnostics, and several document (e.g. `cursor.rs` `asi()`, `punctuation.rs` `<!--`, `string.rs`, `numeric.rs`) that the `#[cold]` trampoline exists to keep the ~232-byte `OxcDiagnostic` return buffer out of the hot function's stack frame. `cold_path` only sets branch weights — it does not outline code or stack usage — so replacing those sites would regress that. `cold_branch`'s doc comment now explains when to use which. One small unlock while here: the comment in `skip_multi_line_comment` saying we "can't use `return` in a closure" to jump to the faster post-line-break search — that limitation is gone now the closure is gone; left as a possible follow-up since it's a behavior change. Verified: - `cargo test -p oxc_parser` and clippy clean. - Parser conformance (test262 / babel / typescript / misc): **zero snapshot diffs**. - Codegen-wise the replaced sites were tiny closures that inlined into the trampoline anyway; CodSpeed on this PR is the final perf gate. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
graphite-app
Bot
force-pushed
the
refactor-cold-path
branch
from
July 12, 2026 01:01
bb67820 to
d302b72
Compare
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.
Rust 1.95 stabilized
std::hint::cold_path, re-exported viaoxc_data_structures::branch_hintsin #24368. This replaces thecold_branchclosure trampoline withcold_path()at the 14 call sites where the hint only guides branch layout — straight-line code instead of closure ceremony.The other 10 sites keep
cold_branchdeliberately: they build diagnostics, and several document (e.g.cursor.rsasi(),punctuation.rs<!--,string.rs,numeric.rs) that the#[cold]trampoline exists to keep the ~232-byteOxcDiagnosticreturn buffer out of the hot function's stack frame.cold_pathonly sets branch weights — it does not outline code or stack usage — so replacing those sites would regress that.cold_branch's doc comment now explains when to use which.One small unlock while here: the comment in
skip_multi_line_commentsaying we "can't usereturnin a closure" to jump to the faster post-line-break search — that limitation is gone now the closure is gone; left as a possible follow-up since it's a behavior change.Verified:
cargo test -p oxc_parserand clippy clean.🤖 Generated with Claude Code