Skip to content

perf(allocator): mark ReplaceWith panic path cold#24515

Open
camc314 wants to merge 1 commit into
mainfrom
codex/cold-replace-with-panic-path
Open

perf(allocator): mark ReplaceWith panic path cold#24515
camc314 wants to merge 1 commit into
mainfrom
codex/cold-replace-with-panic-path

Conversation

@camc314

@camc314 camc314 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Mark ReplaceWith's write_dummy helper as cold.

The helper is only reached while unwinding from a panic in a replacer closure. Telling the optimizer that this path is cold helps keep its allocator and dummy-construction code out of hot code layout and improves inlining decisions in unwind builds.

@camc314 camc314 requested a review from overlookmotel as a code owner July 14, 2026 15:30
Copilot AI review requested due to automatic review settings July 14, 2026 15:30

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the A-allocator Area - Allocator label Jul 14, 2026
@camc314 camc314 changed the title perf(allocator): mark ReplaceWith panic path cold perf(allocator): mark ReplaceWith panic path cold Jul 14, 2026
@codspeed-hq

codspeed-hq Bot commented Jul 14, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 9 skipped benchmarks1


Comparing codex/cold-replace-with-panic-path (64d70f7) with main (ca4a4a7)

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

Copy link
Copy Markdown
Member

I don't think this makes any difference. #[inline(never)] is already present, for this exact reason.

And, as far as I know, #[cold] primarily affects branch layout. But in this case, there's no branch to hint - write_dummy is called from drop unconditionally.

But why ReplaceWith seems to have had a small negative perf effect in transformer (at least according to Codspeed) is a mystery to me, so I may well be wrong.

What is Mr Codex telling you?

@overlookmotel

overlookmotel commented Jul 14, 2026

Copy link
Copy Markdown
Member

Oh actually, I'm pretty sure this cannot account for the perf drop. Our benchmarks are built with panic = "abort", so all the drop guard code is deleted by compiler anyway. Whether it's marked #[cold] or not is irrelevant to the perf change - it must be, because that code isn't there at all in the assembly.

Whether it's a good idea regardless, I don't fully know. I don't think so. But I imagine you have info that contradicts my assumptions, which motivated this PR. I'd like to know what it is!

@camc314

camc314 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Whether it's a good idea regardless, I don't fully know. I don't think so. But I imagine you have info that contradicts my assumptions, which motivated this PR. I'd like to know what it is!

See my msg in Gchat for the actual replace with perf problem.

This was unrelated that i noticed, from my (admittedly limited understanding)

For cold:

Place it in a separate “cold” section of the binary.
  • Optimize for smaller code rather than speed.
  • Assume branches leading to it are unlikely.
  • Improve instruction-cache locality for the hot path.

whereas inline never just discourages inlining.

But, both of these are just suggestions to the compiler!

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

overlookmotel commented Jul 15, 2026

Copy link
Copy Markdown
Member

Merge activity

  • Jul 15, 3:38 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Jul 15, 3:38 PM UTC: overlookmotel added this pull request to the Graphite merge queue.
  • Jul 15, 3:44 PM UTC: The Graphite merge queue couldn't merge this PR because it was not satisfying all requirements (Failed CI: 'Test NAPI Compiler').

## Summary

Mark ReplaceWith's write_dummy helper as cold.

The helper is only reached while unwinding from a panic in a replacer closure. Telling the optimizer that this path is cold helps keep its allocator and dummy-construction code out of hot code layout and improves inlining decisions in unwind builds.
@graphite-app graphite-app Bot force-pushed the codex/cold-replace-with-panic-path branch from 64d70f7 to 7ca9575 Compare July 15, 2026 15:39
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-allocator Area - Allocator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants