Skip to content

backend: batch completions to the owner so one wake settles many calls #1178

Backlog

Description

@Yaraslaut

Summary

Under load, the owner executor is the bottleneck of local dispatch, and much of its time goes into the kernel to sleep and be woken. Each settled call sends its own task to the owner. When the owner is asleep, each of those tasks costs a futex wake on the worker side and a futex wait on the owner side. Batching the completions that are ready into one owner task, so that one wake drains many, is the remaining lever on throughput.

Evidence (measured)

  • Setup: 64 calls in flight, 8 pool workers, owner on its own thread.
  • Measured with perf record --call-graph dwarf, x86-64 Linux, Release.
Calls/s Owner thread, share of all samples Owner thread, kernel Kernel share of the owner
Before #1176 ~63k 43.68% 30.21% 69%
After #1176 (pool spins 25 µs) ~211k 42.24% 12.43% 29%

Not verified

  • What the remaining 29% is. It was not broken down by kernel symbol after perf: cheaper local dispatch, linear handler teardown, observability build switch #1176. Whether it is still mostly futex traffic is inferred from the before profile, not measured.
  • Whether batching recovers it. That was not prototyped. With one call in flight there is nothing to batch, so single-call latency would not improve. Only concurrent load can gain.
  • Owner executors other than a thread blocked on a condition variable. The Qt event loop, MainThreadExecutor and the WASM main thread wake differently and were not profiled.

Direction

  • Completions from pool workers go into a per-owner MPSC queue. Only the transition from empty to non-empty posts one drain task to the owner, which settles everything queued.
  • Invariants to keep: settle order per handler, owner affinity of Completion, and .then attached on the owner.
  • This changes how Completion reaches the owner, so the relevant spec pages (docs/spec/core/bridge.md, backend.md, executor.md) come first.

What would change the verdict

Activity

  1. added
    enhancement
    area: core
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions