diff --git a/.changeset/stream-atomics.md b/.changeset/stream-atomics.md deleted file mode 100644 index 1df7c2b..0000000 --- a/.changeset/stream-atomics.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -'moroutine': minor ---- - -Atomics-based backpressure for streams and channels; new `Int32Atomic#waitAsync` / `#notify` - -**New public API on `Int32Atomic`**: - -```ts -const slot = int32atomic(); -// Park until the slot holds a value other than `expected`, with optional timeout. -await slot.waitAsync(0); // 'ok' | 'not-equal' | 'timed-out' -await slot.waitAsync(0, 100 /*ms*/); -// Wake waiters on this slot. -slot.notify(); // wake all -slot.notify(2); // wake at most 2 -``` - -Matches `Atomics.waitAsync` / `Atomics.notify` semantics; returns `'not-equal'` synchronously (no microtask hop) if the slot already holds something different from `expected`. - -**Streams and channels use atomics for backpressure**: streaming tasks and `channel()` no longer rely on `pause`/`resume` port messages for flow control. Internally, a `SharedArrayBuffer` tracks per-endpoint `inflight` and `state`; the producer parks on `Atomics.waitAsync` when the `highWaterMark` cap is reached and resumes when the consumer drains below it. Behavior-equivalent and much tighter under backpressure (worst-case buffering drops from ~10-20× `highWaterMark` to `highWaterMark + 1-2`). - -**`highWaterMark` option now honored** for both `run(streamTask, { highWaterMark })` and `channel(src, { highWaterMark })`. Previously read and discarded in the streaming path. - -**Significant throughput improvements** on streaming and channel fan-out: - -- Worker → parent stream: ~66K items/s → ~750K items/s (11×) -- Round-trip stream: ~39K items/s → ~425K items/s (11×) -- Channel fan-out at 8 consumers: ~412K items/s → ~546K items/s (+33%) -- Per-task dispatch: ~289K → ~328K (+14%) - -No changes to user-facing API shape beyond the `Int32Atomic` additions. diff --git a/CHANGELOG.md b/CHANGELOG.md index 2840385..32e11fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,37 @@ # moroutine +## 1.2.0 + +### Minor Changes + +- 24741da: Atomics-based backpressure for streams and channels; new `Int32Atomic#waitAsync` / `#notify` + + **New public API on `Int32Atomic`**: + + ```ts + const slot = int32atomic(); + // Park until the slot holds a value other than `expected`, with optional timeout. + await slot.waitAsync(0); // 'ok' | 'not-equal' | 'timed-out' + await slot.waitAsync(0, 100 /*ms*/); + // Wake waiters on this slot. + slot.notify(); // wake all + slot.notify(2); // wake at most 2 + ``` + + Matches `Atomics.waitAsync` / `Atomics.notify` semantics; returns `'not-equal'` synchronously (no microtask hop) if the slot already holds something different from `expected`. + + **Streams and channels use atomics for backpressure**: streaming tasks and `channel()` no longer rely on `pause`/`resume` port messages for flow control. Internally, a `SharedArrayBuffer` tracks per-endpoint `inflight` and `state`; the producer parks on `Atomics.waitAsync` when the `highWaterMark` cap is reached and resumes when the consumer drains below it. Behavior-equivalent and much tighter under backpressure (worst-case buffering drops from ~10-20× `highWaterMark` to `highWaterMark + 1-2`). + + **`highWaterMark` option now honored** for both `run(streamTask, { highWaterMark })` and `channel(src, { highWaterMark })`. Previously read and discarded in the streaming path. + + **Significant throughput improvements** on streaming and channel fan-out: + - Worker → parent stream: ~66K items/s → ~750K items/s (11×) + - Round-trip stream: ~39K items/s → ~425K items/s (11×) + - Channel fan-out at 8 consumers: ~412K items/s → ~546K items/s (+33%) + - Per-task dispatch: ~289K → ~328K (+14%) + + No changes to user-facing API shape beyond the `Int32Atomic` additions. + ## 1.1.0 ### Minor Changes diff --git a/package.json b/package.json index bb02275..46cc274 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moroutine", - "version": "1.1.0", + "version": "1.2.0", "repository": { "type": "git", "url": "git@tangled.org:divy.zone/moroutine"