Offload functions to worker threads with shared memory primitives for Node.js.

perf(worker): inline arg-resolution loops; adaptive yield for streaming master

Two cleanups on worker-entry.ts: 1. Arg resolution now lives as a small loop at each call site (value task, stream task, and recursive task-arg) instead of behind a resolveArgs helper that returned unknown[] | Promise<unknown[]>. A `needsAsyncResolve(arg)` helper DRYs up the `MessagePort | task-arg` check. The hot-path (value task) keeps the sync-prologue + async-tail structure inline so fully-sync args don't enter async mode at all. 2. Streaming emit loop uses adaptive setImmediate instead of yielding after every emit. Arms a setImmediate whose callback flips a `ticked` flag; if the generator's own awaits naturally tick the loop between emits the flag flips and we skip the forced yield, otherwise a streak of YIELD_EVERY (=16) emits without a tick triggers a forced yield so pause/close can reach us. Net effect: pure-CPU generators jump from ~40K items/s to ~85K (the fixed-yield-every-16 ceiling); I/O-backed generators should approach the no-yield ceiling (~489K) because their awaits tick naturally. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>


+63 -35
1 changed file