ReviewOS

zig-utils/zig-js

ABI: implement process nextTick scheduling

#243
Closed chris opened this 9 days ago ·
9 days ago

Parent: #140 Related: #134, #163, #164, #239

Implement the two shared private-ABI next-tick entry points on a real realm-owned process queue rather than aliasing them to ordinary Promise jobs.

Scope

  • Bun__Process__queueNextTick1
  • Bun__Process__queueNextTick2
  • the directly required process.nextTick queue and checkpoint integration

Acceptance

  • Preserve exact one-argument versus two-argument callback arity, encoded value identity, FIFO order, this behavior, and selected-realm ownership.
  • Drain all next-tick work before Promise microtasks at a host checkpoint; after microtasks, loop when they queued more next-tick work, matching the pinned process queue algorithm.
  • Support reentrant scheduling without front-shifts or duplicate execution, and stop accepting work once process._exiting is true.
  • Validate callbacks and publish abrupt completion through the existing first-pending exception boundary; callback failures must use the process uncaught-exception path without losing remaining rooted jobs.
  • Preserve sibling-realm isolation, reject foreign-VM values, trace every queued function/argument precisely, and remain correct for worker-local microtask queues.
  • Add focused runtime and consumer fixtures, update both inventories and README/API/ABI integration evidence, and report committed verification to the parent issues.

Bun__runDeferredWork remains separate: its opaque scheduler task pointer and lifetime contract are not the process next-tick queue.

9 days ago

Completed on main in implementation commit 084f1c8 and evidence commit b714f56. The two private exports use a distinct precisely rooted realm FIFO with exact argument counts/identity, next-tick-before-Promise ordering, the pinned post-microtask loop, reentrant FIFO behavior, uncaught monitor/capture/listener policy, resumable tails after listener failure, foreign-VM validation, and _exiting suppression. Verification: process matrix 5/5 with zero leaks; Promise matrix 18/18 with zero leaks; active queue-root matrix 3/3 with zero leaks; Home consumer 240/240; Home 241/431 (190 pending); Bun 235/421 (186 pending). The 1,540-sample JSC comparison remains 36a617b because this ABI-only scheduler slice does not change that workload.

Sign in to comment on this issue.