Skip to content

coalesce eventfd wakes across all cross-thread queues (only _postQ coalesces today) #96

Description

@MDA2AV

Severity: medium — performance only, and only for off-reactor producers; but the Kestrel bridge and any thread-pool-hopping handler pays one write(2) syscall per operation.

Problem

ScheduleOnReactor has the right pattern: _postSignalPending guarantees at most one outstanding eventfd write per drain cycle — Reactor.Post.cs#L43-L52.

The other cross-thread producers wake unconditionally, one syscall per item:

Pure on-reactor handlers never hit these (the direct fast paths shortcut), so today's benchmarks don't show it — but the moment continuations hop threads (Kestrel transport, Task.Run, external awaits), it's a syscall per op through the back door.

Suggested fix

One shared _wakePending flag for all queues: producers Interlocked.Exchange after a successful enqueue and write the eventfd only on 0→1; the loop clears it at the top of the iteration before draining (same ordering argument as the existing DrainPostQ comment). The eventfd counter already coalesces kernel-side; this removes the redundant user-side syscalls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions