[Prototype] Batch consecutive await continuations on one fiber (follow-up to #7) - #9
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
RunNextDispatchableMicrotask (and the unmangled v8_qualia_RunNextDispatchableMicrotask) takes the next job off the default microtask queue if it is a promise reaction job with CPED set, and runs it on the current stack the way RunDispatchedMicrotask does. An embedder running a dispatched job on a coroutine can use it to keep running the dispatchable jobs queued right behind it, instead of switching back to the main stack and being handed each one separately. The RunMicrotasks loop re-reads the queue's start and size before every job, so the drain it is nested in continues with the job after them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #7 (stacked on it; merge #7 first). Adds one V8 entry point so node-fibers can run a chain of
awaitcontinuations from fibered code on one fiber instead of switching stacks for each one. Pairs with qualialabs/node-fibers#8.deps/v8/include/v8-microtask-dispatch.hRunNextDispatchableMicrotask(isolate)and the unmangledv8_qualia_RunNextDispatchableMicrotaskdeps/v8/src/runtime/runtime-promise.ccRunDispatchedMicrotask) and return true; otherwise return false and leave the queue aloneThe embedder only calls it while the job #7 dispatched is still nested inside the microtask loop, and only takes jobs from the front, so the order of jobs is unchanged. The
RunMicrotasksbuiltin re-reads the queue's start and size before every job, so the drain it's nested in carries on with the job after the ones taken. No builtin, runtime-function or snapshot changes beyond #7.Results
Same arm64
dev-qualiacontainer as #7, together with qualialabs/node-fibers#8 (FIBERS_AWAIT_REUSE=0gives the #7 behaviour on the same binary):awaits in a fiberawaitin a fiber (each resumes from its own macrotask)awaits outside any fiberThe I/O case is close to the floor for
CORO_PTHREAD: a barerun()+yield()round trip is ~20 us in this Docker VM on stock node. In local qli5 qualia ~80% of dispatchable jobs since boot ran batched (46,624 dispatched, 227,679 batched); startup hooks that await and then block still work, and code that never had a fiber still doesn't get one.🤖 Generated with Claude Code