Skip to content

perf(writer): let the backends report write completions directly - #144

Merged
greenhat616 merged 2 commits into
perf/event-loop-12-loop-pollfrom
perf/event-loop-13-writer-completions
Oct 21, 2026
Merged

greenhat616 merged 2 commits into
perf/event-loop-12-loop-pollfrom
perf/event-loop-13-writer-completions

Conversation

@greenhat616

Copy link
Copy Markdown
Owner

Part 13/13 of the event-loop optimization stack · Perf + review fixes. Stacked on part 12.

  • Backends report write completions directly through a CompletionGuard (exactly once on every path) instead of spawn + oneshot; the pool backend syncs after all workers exit. End to end (10 GiB, mmap): user/sys CPU -2..-4% (two interleaved rounds, low confidence).
  • Fixes from the branch review (codex + antigravity, converged with no Critical/Major).

Each write of the download loop went through a spawned task that sent it
to the backend's worker, awaited the worker's oneshot reply and forwarded
the result to the loop's completion channel. `PendingWriter::new_direct`
now queues the write straight to the mmap, pool, null or compio workers,
with a `CompletionGuard` that the worker completes into that channel; only
a full worker queue still takes a task, which queues the same guarded
write. The guard enters the command before it is queued, so every write
completes exactly once: done, dropped with its queue (a worker that exits
now closes and drains it), with a panicking worker, or with a task that
was never polled. The four backends share one `Command` type.

`PendingWriter::new` keeps the spawned path for any `FileRangeWriter`, now
with the same guard. The pool backend also syncs the file only after all
its workers exited, so a write taken by one worker cannot land after
another worker synced.

Measured end to end with the mmap backend: 2-4% less user and system CPU.
- `TaskRunnerBuilder::connector` takes `impl Into<StreamConnector>`, so a
  connecting future can be passed as is; the docs of `stream`,
  `connect_timeout`, `StreamNotSet` and `TaskOptions::connect_timeout`
  say how they interact and that the singleton task's connection is now
  bounded by the connect timeout.
- The native timer test measures from before the timers exist, and the
  coordination bench no longer requires a queue of one to fill, which
  depends on scheduling.
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