Skip to content

perf(macros): #[inline] the generated immediate dispatch - #296

Merged
unbalancedparentheses merged 1 commit into
mainfrom
perf/inline-immediate-dispatch
Nov 18, 2026
Merged

unbalancedparentheses merged 1 commit into
mainfrom
perf/inline-immediate-dispatch

Conversation

@unbalancedparentheses

Copy link
Copy Markdown
Contributor

Since the module split (#278), rustc no longer inlines the #[actor]-generated __spawned_handle_immediate into SendEnvelope::handle. v0.8.0 inlined the handler body into handle (14 Ir) and called PendingReply::reply out of line (17 Ir). main calls __spawned_handle_immediate out of line (22 Ir) from a bigger handle (30 Ir). That is +22 Ir per send, +3.6% over v0.8.0 on async_ct_send_p1/p2, plus +0.4% to +1.2% on the async request benchmarks. The macro is the same in both versions, so this is a codegen change caused by the new module layout, not new work on the hot path. Bisected on fede: every commit up to d79c041b matches v0.8.0, and 8bbe1c72 (#278) is where it changes.

With #[inline] on the generated method, handler, dispatch and reply() all inline into a 9-Ir handle. Callgrind on fede (gate harness, base main, release v0.8.0):

benchmark v0.8.0 main this PR Δ vs main Δ vs v0.8.0
async_ct_burst 3,550 3,563 3,518 -1.3% -0.9%
async_ct_request_seq 3,050 3,077 3,032 -1.5% -0.6%
async_ct_request_conc16 2,267 2,297 2,252 -2.0% -0.7%
async_ct_send_p1 618 640 597 -6.7% -3.4%
async_ct_send_p2 614 636 593 -6.8% -3.4%
threads_request_seq 2,100 2,050 2,062 +0.6% (noise, ±20) -1.8%

Without this fix, main fails the cumulative release budget in #295. cargo test -p spawned-concurrency -p spawned-macros passes on fede, including trybuild and immediate_dispatch.

Model: no change because an inlining hint changes no behaviour.

@github-actions

Copy link
Copy Markdown

🤖 Gemini Code Review

The change looks good.

Adding #[inline] to the macro-generated __spawned_handle_immediate wrapper in macros/src/actor.rs:640 is a clean, zero-risk way to ensure consistent cross-CGU inlining into the envelope dispatch path without affecting semantics or actor lifecycle behavior.


Automated review by Gemini · gemini-4-argon · custom prompt · 795 in / 671 out · ~$0.01

@github-actions

Copy link
Copy Markdown

🤖 Kimi Code Review

No findings. The #[inline] hint on the generated dispatch method (macros/src/actor.rs:640) is narrowly scoped and does not alter message ordering, actor lifecycle, or concurrency behavior. Using #[inline] rather than #[inline(always)] appropriately leaves the final decision to the compiler, and the changelog clearly documents the regression rationale and benchmark results. No additional tests are necessary for this attribute-only change.


Automated review by Kimi (Moonshot AI) · kimi-k3.1-pro · custom prompt · 772 in / 535 out · ~$0.01

@github-actions

Copy link
Copy Markdown

🤖 Claude Code Review

Review: PR #296, #[inline] on the generated __spawned_handle_immediate

Verdict: Looks good. The change is small, low-risk and well-motivated. Notes below are minor.

Correctness

  • macros/src/actor.rs:640: #[inline] is valid on the generated method, whether it lands in an inherent or a trait impl.
    • It doesn't change semantics, the lifecycle, or message ordering.
    • It is only a hint, so the worst case is the old codegen.
  • The hint is what makes a difference here. The method's only generic is a lifetime (<#turn_lifetime>), and lifetimes don't cause monomorphization. Without #[inline], the body is codegen'd once in a single CGU. Whether it gets inlined into the envelope's dispatch then depends on CGU partitioning, which follows the module layout. That matches the regression described after refactor: split tasks/threads actor.rs, supervision.rs and macros lib.rs into submodules #278.

Things to check

  1. Other generation sites. The diff touches one quote! block, the one that emits the request/reply form. If __spawned_handle_immediate is also generated elsewhere, apply the same attribute there so send and request don't diverge. Possible places include:

    • a send-only / no-reply handler path,
    • a thread-backend expansion,
    • a fallback when the handler isn't await-free.

    The CHANGELOG cites async_ct_send_* improving. That suggests the send path does go through this block, but it's worth confirming no sibling path was missed.

  2. Code size with large handlers. The comment (lines 635–640) says the handler body and reply() get inlined together. For actors with many large handlers, a dispatch match with everything inlined can grow noticeably. Since this is #[inline] and not #[inline(always)], LLVM can still decline, so I think this is acceptable. Just don't escalate to always later without measuring binary size.

  3. Regression protection. The fix depends on a benchmark that the next refactor could silently undo. A cheap guard is a macro-expansion snapshot test (e.g. macrotest/expandtest) asserting the attribute is emitted. That way someone dropping it during a refactor gets a test failure, not just a perf-gate blip.

Style / maintainability

No concurrency, safety, or error-handling concerns. Approve after confirming point 1.


Automated review by Claude · claude-opus-5-5 · custom prompt · 1.1k in / 2.0k out · ~$0.05

@github-actions

Copy link
Copy Markdown

🤖 DeepSeek Code Review

I only have the diff to review, but the change is straightforward and isolated.

Summary

macros/src/actor.rs adds #[inline] to the generated __spawned_handle_immediate function, backed by benchmark results in CHANGELOG.md.

Correctness

The generated attribute is syntactically valid and does not change runtime semantics. #[inline] is only a hint to the compiler, so there is no risk to memory safety, concurrency, or actor lifecycle semantics from this change.

Performance

The rationale in the comment and changelog is clear: after the module split in #278 the compiler stopped inlining this dispatch function, causing a measurable instruction-count regression. Adding #[inline] restores the inlining behavior. This is an appropriate use of the attribute.

Minor considerations

  • The comment notes that inlining is left to compiler heuristics. If this path is extremely performance-sensitive, #[inline(always)] could be considered, but that often increases code size and compile time and is rarely warranted. #[inline] is a reasonable middle ground here.
  • The changelog cites very precise benchmark numbers without specifying compiler version/flags; those numbers may drift across compiler releases, but that’s a documentation concern rather than a code issue.

Verdict

LGTM. The change is a small, well-explained compiler hint with no apparent correctness or concurrency concerns.


Automated review by DeepSeek · deepseek-v4-pro · custom prompt · 804 in / 3.3k out · ~$0.01

@github-actions

Copy link
Copy Markdown

🤖 Codex Code Review

No findings. The added #[inline] on the generated immediate-dispatch method is a reasonable optimization hint and preserves existing behavior. I found no correctness, concurrency, lifecycle, or memory-safety concerns in this diff.

The benchmark improvements reported in the changelog were not independently verified.


Automated review by OpenAI Codex · gpt-6.1-sol · custom prompt · 37.6k in / 250 out · ~$0.03

@github-actions

Copy link
Copy Markdown

🤖 Grok Code Review

This change is sound. #[inline] on the generated __spawned_handle_immediate in macros/src/actor.rs is the right fix for the post-#278 cross-module inlining regression, and it does not change dispatch semantics, ordering, or shutdown behavior.

#[inline] (not always) is the better hint here. The function is generic over #turn_lifetime and monomorphized at the envelope call site, so the body is already visible in-crate; the attribute only lowers the heuristic threshold. Forcing always would risk i-cache bloat once handler bodies grow, and the changelog numbers already show the hint is enough.

No concurrency or safety issues: inlining a &mut self await-free method does not affect borrows, CancellationToken, or reply ordering. Annotating only this path (not the .await handler above it) is correct — that state machine should stay out of the send path.

The source comment is worth keeping so the attribute is not dropped as redundant. It lives in the macro source, not in expanded user code.


Automated review by Grok (xAI) · grok-4.7 · custom prompt · 1.9k in / 3.2k out · ~$0.02

@unbalancedparentheses
unbalancedparentheses added this pull request to the merge queue Nov 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 17, 2026
After the module split (#278) the compiler stopped inlining
__spawned_handle_immediate into SendEnvelope::handle, adding 22
instructions per send: +3.6% over v0.8.0 on async_ct_send_p1/p2, which
the cumulative perf budget against the release would fail. With the
hint, handler body and reply() inline again and every gated async
benchmark is below v0.8.0.
@unbalancedparentheses
unbalancedparentheses force-pushed the perf/inline-immediate-dispatch branch from 935e22b to c23a8ea Compare November 17, 2026 23:29
@unbalancedparentheses
unbalancedparentheses added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 881054f Nov 18, 2026
31 checks passed
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.

1 participant