Skip to content

perf(allocator): add #[cold] annotations to error handling functions#18181

Merged
graphite-app[bot] merged 1 commit intomainfrom
perf/cold-path-annotations
Jan 18, 2026
Merged

perf(allocator): add #[cold] annotations to error handling functions#18181
graphite-app[bot] merged 1 commit intomainfrom
perf/cold-path-annotations

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Jan 18, 2026

Summary

  • Add #[cold] and #[inline(never)] annotations to error/panic functions in oxc_allocator
  • Improves branch prediction and code layout for hot allocation paths

Functions annotated

File Function Change
bump.rs allocation_size_overflow Added #[cold]
bumpalo_alloc.rs new_layout_err Added #[cold] + #[inline(never)]
bumpalo_alloc.rs handle_alloc_error Added #[cold] + #[inline(never)]
vec2/raw_vec.rs capacity_overflow Added #[cold] + #[inline(never)]

Impact

The #[cold] attribute tells the compiler to:

  1. Assume branches leading to these functions are unlikely
  2. Move cold code away from hot paths (improves i-cache locality)
  3. Avoid inlining cold functions into hot callers

Test plan

  • cargo test -p oxc_allocator passes

🤖 Generated with Claude Code

@Boshen Boshen requested a review from overlookmotel as a code owner January 18, 2026 11:51
Copilot AI review requested due to automatic review settings January 18, 2026 11:51
@github-actions github-actions bot added the C-performance Category - Solution not expected to change functional behavior, only performance label Jan 18, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds performance optimization attributes (#[cold] and #[inline(never)]) to error handling and panic functions in the oxc_allocator crate to improve branch prediction and code layout for hot allocation paths.

Changes:

  • Added #[cold] attribute to allocation_size_overflow in bump.rs (already had #[inline(never)])
  • Added both #[cold] and #[inline(never)] attributes to new_layout_err and handle_alloc_error in bumpalo_alloc.rs
  • Added both #[cold] and #[inline(never)] attributes to capacity_overflow in vec2/raw_vec.rs

Reviewed changes

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

File Description
crates/oxc_allocator/src/bump.rs Added #[cold] to allocation_size_overflow function
crates/oxc_allocator/src/bumpalo_alloc.rs Added #[cold] and #[inline(never)] to new_layout_err and handle_alloc_error functions
crates/oxc_allocator/src/vec2/raw_vec.rs Added #[cold] and #[inline(never)] to capacity_overflow function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 18, 2026

Merging this PR will not alter performance

✅ 42 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing perf/cold-path-annotations (0dd3702) with main (37482eb)

Open in CodSpeed

Footnotes

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

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Jan 18, 2026
Copy link
Member Author

Boshen commented Jan 18, 2026

Merge activity

…18181)

## Summary

- Add `#[cold]` and `#[inline(never)]` annotations to error/panic functions in oxc_allocator
- Improves branch prediction and code layout for hot allocation paths

### Functions annotated

| File | Function | Change |
|------|----------|--------|
| `bump.rs` | `allocation_size_overflow` | Added `#[cold]` |
| `bumpalo_alloc.rs` | `new_layout_err` | Added `#[cold]` + `#[inline(never)]` |
| `bumpalo_alloc.rs` | `handle_alloc_error` | Added `#[cold]` + `#[inline(never)]` |
| `vec2/raw_vec.rs` | `capacity_overflow` | Added `#[cold]` + `#[inline(never)]` |

### Impact

The `#[cold]` attribute tells the compiler to:
1. Assume branches leading to these functions are unlikely
2. Move cold code away from hot paths (improves i-cache locality)
3. Avoid inlining cold functions into hot callers

## Test plan

- [x] `cargo test -p oxc_allocator` passes

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the perf/cold-path-annotations branch from 0dd3702 to 46cd73d Compare January 18, 2026 12:12
@graphite-app graphite-app bot merged commit 46cd73d into main Jan 18, 2026
22 checks passed
@graphite-app graphite-app bot deleted the perf/cold-path-annotations branch January 18, 2026 12:18
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants