Skip to content

feat(data_structures): add likely and unlikely functions#24368

Merged
graphite-app[bot] merged 1 commit into
mainfrom
om/07-10-feat_data_structures_add_likely_and_unlikely_functions
Jul 10, 2026
Merged

feat(data_structures): add likely and unlikely functions#24368
graphite-app[bot] merged 1 commit into
mainfrom
om/07-10-feat_data_structures_add_likely_and_unlikely_functions

Conversation

@overlookmotel

@overlookmotel overlookmotel commented Jul 10, 2026

Copy link
Copy Markdown
Member

#24359 bumped our MSRV to 1.95.0.

Now at last we have a decent way to guide branch layout: std::hint::cold_path. 🍾

Add the likely and unlikely functions that Rust's docs suggest as simple ways to use this capability.

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@overlookmotel
overlookmotel marked this pull request as ready for review July 10, 2026 20:10
Copilot AI review requested due to automatic review settings July 10, 2026 20:10
@overlookmotel overlookmotel self-assigned this Jul 10, 2026

Copilot AI 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.

Pull request overview

Adds an opt-in branch_hints module to oxc_data_structures providing lightweight branch prediction hint helpers built on Rust 1.95’s std::hint::cold_path, aligning with Rust’s recommended pattern for guiding cold/likely code layout.

Changes:

  • Introduces branch_hints::{likely, unlikely} plus a re-export of std::hint::cold_path.
  • Wires the new module behind a branch_hints Cargo feature and includes it in the crate’s all feature.
  • Documents the new utility in the crate README and adds basic unit tests (including const-context usage).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
crates/oxc_data_structures/src/lib.rs Exposes the new branch_hints module behind the branch_hints feature flag.
crates/oxc_data_structures/src/branch_hints.rs Implements likely/unlikely, re-exports cold_path, and adds tests.
crates/oxc_data_structures/README.md Mentions the new branch hint utilities in the feature overview.
crates/oxc_data_structures/Cargo.toml Adds the branch_hints feature and includes it in all.

Comment thread crates/oxc_data_structures/src/branch_hints.rs
Comment thread crates/oxc_data_structures/src/branch_hints.rs
@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Jul 10, 2026

overlookmotel commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

Merge activity

[#24359](#24359) bumped our MSRV to 1.95.0.

Now *at last* we have a decent way to guide branch layout: [`std::hint::cold_path`](https://doc.rust-lang.org/stable/core/hint/fn.cold_path.html). 🍾

Add the `likely` and `unlikely` functions that Rust's docs suggest as simple ways to use this capability.
@graphite-app
graphite-app Bot force-pushed the om/07-10-feat_data_structures_add_likely_and_unlikely_functions branch from a4eb09b to ddab89a Compare July 10, 2026 20:20
@codspeed-hq

codspeed-hq Bot commented Jul 10, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 57 untouched benchmarks
⏩ 14 skipped benchmarks1


Comparing om/07-10-feat_data_structures_add_likely_and_unlikely_functions (a4eb09b) with main (3ff0234)

Open in CodSpeed

Footnotes

  1. 14 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.

@graphite-app
graphite-app Bot merged commit ddab89a into main Jul 10, 2026
30 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Jul 10, 2026
@graphite-app
graphite-app Bot deleted the om/07-10-feat_data_structures_add_likely_and_unlikely_functions branch July 10, 2026 20:25
graphite-app Bot pushed a commit that referenced this pull request Jul 12, 2026
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)
Boshen added a commit that referenced this pull request Jul 14, 2026
### 🚀 Features

- 616bfa2 minifier: Remove unreachable code after terminating statements
(#24441) (Dunqing)
- ddab89a data_structures: Add `likely` and `unlikely` functions
(#24368) (overlookmotel)
- a3a39f9 react_compiler: Implement enableEmitHookGuards codegen
(#24329) (Boshen)
- b79eef7 minifier: Apply De Morgan's law to negated comparison chains
in jump guards and loop tests (#24279) (Dunqing)
- 34ff7b4 minifier: Drop write-only property assignments to unused local
bindings by default (#24112) (Dunqing)
- 1b829d8 semantic: Record const enums in EnumData (#24268) (Dunqing)
- ba0944c semantic: Add `Scoping::set_symbol_span` (#24221) (camc314)

### 🐛 Bug Fixes

- 7d33363 minifier: Preserve guaranteed throws from class heritage
evaluation (#24349) (Dunqing)
- 058a62f semantic: Track ambient contexts in `SemanticBuilder` (#24327)
(camc314)
- 721eb0b transformer/decorator: Scope accessor class binding (#24330)
(camc314)
- 1ebdce3 semantic: Allow reserved keywords in ambient declaration types
(#24325) (camc314)
- 460176a track-memory-allocations: Exclude arena chunks from Sys allocs
(#24292) (Dunqing)
- af4922b transformer: Clear lowered namespace redeclarations (#24300)
(camc314)
- ffd2765 semantic: Mark declared computed `MethodDefinition`s as type
references (#24296) (camc314)
- f17514b isolated-declarations: Emit const readonly fields as types
(#24288) (camc314)
- 40f769d minifier: Make `__proto__` write tracking execution-order
independent (#24280) (Dunqing)
- 6371fed transformer: Remove stale enum member bindings (#24272)
(camc314)
- f05dfab transformer: Correct symbol flags for lowered namespaces
(#24271) (Dunqing)
- 84eeb55 transformer: Correct symbol flags for lowered enums (#24269)
(Dunqing)
- c3057da transformer: Preserve generated class binding spans (#24220)
(camc314)
- 8260096 transformer: Correct span for lowered namespace symbol
(#24222) (camc314)
- 42d00d3 semantic: Mark declared class heritage as type references
(#24237) (camc314)
- 588d997 semantic: Mark TS `PropertyDefinition`s computed fields as
type references (#24233) (camc314)
- 9b95632 semantic: Mark computed method keys in `TSMethodSignature`s as
type references (#24232) (camc314)

### ⚡ Performance

- 5b26643 transformer_plugins: Dispatch global defines by trailing name
(#23666) (Boshen)
- dce0f29 react_compiler: Replace all compiled functions in a single AST
walk (#24403) (Boshen)
- f85f0d8 ast: Delegate inherited enum variants in clone_in and estree
derives (#23555) (Boshen)
- 3ff0234 allocator: Remove `unwrap` from `ReplaceWith` (#24365)
(overlookmotel)
- ab22e80 transformer: Fix Rust 1.97 performance regression (#24354)
(camc314)
- b47585c parser: Use `ReplaceWith` instead of `TakeIn` (#24018)
(overlookmotel)
- b227a06 minifier: Use `ReplaceWith` instead of `TakeIn` (#24017)
(overlookmotel)

Co-authored-by: Boshen <[email protected]>
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