Skip to content

perf: specialize spawn_fold serving path - #7

Merged
colmugx merged 4 commits into
mainfrom
perf/specialize-spawn-fold
Sep 24, 2026
Merged

colmugx merged 4 commits into
mainfrom
perf/specialize-spawn-fold

Conversation

@colmugx

@colmugx colmugx commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Why

spawn_fold is the dominant tell-oriented actor shape, but it currently delegates to the fully generic command/query loop with Query = Unit and Reply = Unit. Every receipt ask therefore still flows through the generic query callback and tuple-return path.

What changed

  • give spawn_fold its own loop and serving path;
  • handle Tell(cmd) directly through the command handler;
  • handle Ask(()) as a FIFO receipt without invoking a generic query callback or constructing a (State, Reply) pair;
  • mark the fold command handler local in the specialized serving loop so MoonBit can inline the function parameter;
  • keep the same mailbox, batching, cleanup, cancellation, diagnostics and public API semantics.

Measured result

On the same GitHub runner host (runnervmlun5p), AMD EPYC 9V74, same MoonBit toolchain:

  • tell median: 11.914 M/s -> 12.677 M/s (+6.4%)
  • handler-cost median: 457.8k/s -> 458.3k/s (flat)
  • hotcold-16 P99: 125 us -> 128 us (effectively flat)

All repository tests passed in the experimental benchmark run.

Compiler note

I also tested propagating #locals(on_cmd) one level outward onto fuwaroid_loop_fold. MoonBit rejects that with E4163 (This parameter is expected to be local, but it escapes) because the handler is captured by the handle_cancellation async closure. The locality hint therefore remains on the innermost fuwaroid_serve_fold, where it is valid and benchmarked.

Give spawn_fold a dedicated serving path that handles Tell directly and treats Unit asks as FIFO receipts, removing the generic query callback and state/reply tuple from the dominant tell-oriented actor shape. Mark the command handler local for MoonBit parameter inlining.
@colmugx
colmugx merged commit d12814e into main Sep 24, 2026
1 check passed
@colmugx
colmugx deleted the perf/specialize-spawn-fold branch September 24, 2026 05:25
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