Skip to content

perf(io): index parked descriptor waiters and timers - #1442

Closed
oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/1250-indexed-io-waiters
Closed

oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/1250-indexed-io-waiters

Conversation

@oxura

@oxura oxura commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Status: draft — protected compiler budget decision required

Addresses #1250. This is not merge-ready and not counted as a completed issue: gates/repo.ts reports 53 / 54 because bend2/comp.ts is 67,176 ttok, above its permanent 64,000 cap. Unchanged main 60fa05dc28f847382554dae6ee76cd1b2911bcc3 is 63,905 ttok. The implementation adds 3,271 tokens; the excess is 3,176. AGENTS.md reserves budget changes to Taelin. I have not edited the gate/cap, split the compiler to evade it, deleted unrelated functionality, or bypassed a hook.

The issue mentions an existing working branch. Please point me to that intended implementation/integration boundary if this overlaps it; otherwise a maintainer budget decision is required before this can be made ready.

Change

  • Replace per-pass traversal of parked descriptors with persistent level-triggered epoll (Linux) / kqueue (macOS), indexed descriptor read/write waiter rings and indexed deadline/ready heaps.
  • Preserve deadline and registration ordering, multiple waiters sharing one FD, re-parking, interrupted waits, worker wakeups and channel timer cancellation. Both parked and already-ready timer records remain removable before their storage is freed.
  • JS uses dynamic numeric-FD Map/Set membership, retained poll buffers/views and a cancellation token; channel wakeups remove the timer directly instead of searching all parked requests.
  • No per-descriptor native allocation: inline hash rows grow geometrically; an existing descriptor or reusable tombstone does not trigger an unnecessary resize.
  • Remove obsolete select bindings/macros and update the interruption comments and existing runtime-paper source. No release changelog edit: maintainers own release commits.

Actual Linux runtime qualification

Sixteen existing public IO programs were compiled and run natively and under Bun: timers/order, EINTR, spawned TCP connections, queued-accept fairness, receive/send deadlines, bytes and validation errors, EOF, UDP readiness, listener close, channel timeouts/close, concurrent Process.run/EOF and IO.within under a busy pipeline.

31 / 32 program-lane checks pass. The untouched native chan_try_late.bend fails identically on the unchanged baseline and this branch: B: 767263360, S: sent, A: ready got 7, then bend: deadlock: every computation waits on a channel. Its baseline and indexed Bun runs both pass with the original expected output. I have not suppressed, altered or presented the native baseline failure as passing.

New poll_shared_fd regression uses a real socketpair: two waiters share its readable FD, the first consumes a and re-parks, the second must consume b, and the first's next wake consumes c. Exact ordering/re-arming and completion pass on both baseline/final native and Bun backends. The final native consumer also passes ASan + UBSan with leak detection, output 3, exit 0 and empty diagnostics.

Actual serial-arrival scaling

A real writer thread/worker sends one byte to each watched socket and waits for acknowledgement before the next arrival; all remaining connections stay parked. Construction is outside the timed interval. Three interleaved before/after samples per size and backend; every sample completes every arrival. Median milliseconds on this Linux x86_64 host, not a universal performance claim:

Backend Watched connections Baseline ms Indexed ms
Native 128 1.297 0.975
Native 512 9.179 3.878
Native 2,048 103.133 16.229
Native 4,096 389.531 33.236
Bun 128 3.378 2.327
Bun 512 17.880 7.114
Bun 2,048 180.321 23.106
Bun 4,096 606.121 50.065

Limits / review boundary

  • Protected repository gate is failing, for the budget above; readiness awaits the maintainer decision. No green-full-gate claim.
  • macOS kqueue code is implemented but has not been built or exercised on this Linux workstation.
  • Mini-cluster test/perf gates and hosted CI are not claimed; the local real consumer results above are the exercised evidence.
  • Existing native late-channel fixture failure is disclosed and unchanged. No interpreter/native effect parity claim beyond the exercised backends.

AI-assisted: omp / GPT-6.1 Sol, working alone without subagents.

@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Closing because of being stale and a change too big (3k ttok on comp.ts) for the current budget. Thanks

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.

2 participants