Skip to content

refactor(parser): use cold_path for pure branch-layout hints#24380

Merged
graphite-app[bot] merged 1 commit into
mainfrom
refactor-cold-path
Jul 12, 2026
Merged

refactor(parser): use cold_path for pure branch-layout hints#24380
graphite-app[bot] merged 1 commit into
mainfrom
refactor-cold-path

Conversation

@Boshen

@Boshen Boshen commented Jul 11, 2026

Copy link
Copy Markdown
Member

Rust 1.95 stabilized std::hint::cold_path, 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

@github-actions github-actions Bot added the A-parser Area - Parser label Jul 11, 2026
@codspeed-hq

codspeed-hq Bot commented Jul 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 9 skipped benchmarks1


Comparing refactor-cold-path (bb67820) with main (d117011)

Open in CodSpeed

Footnotes

  1. 9 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Jul 12, 2026

overlookmotel commented Jul 12, 2026

Copy link
Copy Markdown
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
graphite-app Bot force-pushed the refactor-cold-path branch from bb67820 to d302b72 Compare July 12, 2026 01:01
@graphite-app
graphite-app Bot merged commit d302b72 into main Jul 12, 2026
30 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Jul 12, 2026
@graphite-app
graphite-app Bot deleted the refactor-cold-path branch July 12, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants