[Prototype] Reuse one dispatch fiber and batch await continuations (follow-up to #6) - #8
Draft
jbaczuk-qualia wants to merge 1 commit into
Draft
jbaczuk-qualia wants to merge 1 commit into
jbaczuk-qualia wants to merge 1 commit into
Conversation
Instead of a new hidden fiber per dispatched job, keep one long-lived hidden dispatch fiber. After each job it runs the dispatchable jobs queued right behind it (Fiber.__runNextDispatchable, needs the matching node patch), so a chain of awaits in fibered code costs one switch onto the fiber and one back instead of two per await. A job that blocks keeps the fiber and the next dispatch starts a new one; a fiber that was parked and later resumed never pulls in other jobs. FIBERS_AWAIT_REUSE=0 restores one new fiber per job. Fiber.microtasksBatched counts jobs run without a switch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 2, 2026
Draft
Draft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Optional follow-up to #6 (stacked on it; merge #6 first). Needs qualialabs/node#9. Instead of a new hidden fiber per dispatched job, keep one long-lived hidden dispatch fiber, and after each job let it run the dispatchable jobs queued right behind it, so a chain of
awaits in fibered code costs one switch onto the fiber and one back instead of two perawait.fibers_async.jsreusingDispatcher: runs jobs on the dispatch fiber and, while it is still the dispatch fiber, keeps callingFiber.__runNextDispatchable(). A job that blocks keeps the fiber (it's parked inside that job) and the next dispatch starts a new one, the same trick as znewsham's drain fiber in this repo's #7. A parked fiber that is later resumed never pulls in other jobs. A dispatch that arrives while the dispatch fiber itself is running (nested drain) falls back to a one-off fiber.FIBERS_AWAIT_REUSE=0(or a node without node#9) gives the #6 behaviour;Fiber.microtasksBatchedcounts jobs run without a switchsrc/fibers.ccFiber.__runNextDispatchable(), defined only whendlsymfindsv8_qualia_RunNextDispatchableMicrotaskTesting
On #6's node 18 build plus node#9, arm64
dev-qualiacontainer:test-microtask-fibers.js(withFiber.currentswapped for the running fiber,poolSize = 1e9): same as on [Prototype] Run await continuations from fibers in hidden fibers (needs node#7) #6, 7/7 behaviour tests pass including "a parked microtask does not stall other promises" and "resuming a parked fiber does not drain unrelated microtasks mid-callback"; the 100k park/resume cycle test still exceeds its 10 s timeout (~9.7 s for the cycles alone; every park needs its own fiber).should not double-wrap callbacksis gone).test/: unchanged (pool.js/cleanup.jspthreadcoro_destroysegfault as on stock).Can't wait without a fiber.awaits in a fiberawaitin a fiber🤖 Generated with Claude Code