[Prototype] Node 24: let node-fibers run await continuations on a fiber (port of #7 + #9) - #10
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
…node 24) Port of the node 18 fiber-await prototype (#7 + #9) to V8 13.6: - The microtask runner offers fulfill/reject reaction jobs whose continuation-preserved embedder data (CPED) is set to an embedder callback (include/v8-microtask-dispatch.h, Runtime_DispatchMicrotask). - RunDispatchedMicrotask runs a taken job through a private one-job queue with the same CPED save/clear/restore MicrotaskQueue:: RunMicrotasks does around a drain (V8 13 keeps CPED on the isolate). - RunNextDispatchableMicrotask lets the embedder run the dispatchable jobs queued right behind one it is running, without switching stacks. - Unmangled v8_qualia_* entry points for dlsym. Unlike V8 10, V8 13 already restores the caller's CPED after a drain, so the builtin needs no CPED change beyond the dispatch hook. Node 24's AsyncContextFrame uses the same CPED slot; the embedder (node-fibers) only enables dispatch under --no-async-context-frame. 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
Port of the node 18 fiber-await prototype (#7 + #9) to node 24.21.0 / V8 13.6, stacked on #6 (
custom-v24-pthread; merge #6 first). Lets node-fibers run the code after anawait(and.thencallbacks) registered inside a fiber on a hidden fiber, and batch runs of them on one fiber. Pairs with qualialabs/node-fibers#9. One commit, V8 only:deps/v8/include/v8-microtask-dispatch.h(new, identical to #7/#9)SetMicrotaskDispatchCallback,RunDispatchedMicrotask,RunNextDispatchableMicrotaskand unmangledv8_qualia_*entry points fordlsymdeps/v8/src/builtins/builtins-microtask-queue-gen.ccRuntime::kDispatchMicrotask; skip the job if the embedder took itdeps/v8/src/runtime/runtime-promise.cc,runtime.hRunMicrotasksbuiltin, plus batching of the dispatchable jobs queued right behindWhat differs from node 18
Tagged<>,DirectHandle,RETURN_FAILURE_IF_EXCEPTION, newTryRunMicrotaskssignature): mechanical.MicrotaskQueue::RunMicrotasksalready saves and restores the caller's CPED around a drain, so unlike [Prototype] Node 18: let node-fibers run await continuations on a fiber (V8 microtask dispatch) #7 the builtin needs no CPED change; the private one-job runner does the same save/clear/restore.--no-async-context-frame. node-fibers only enables dispatch with the flag (fibers needs it on node 24 anyway); the tag it uses istrue, which lives in read-only space, so the per-archived-thread GC visit of the CPED root (the unapplied4172f779fix) can't corrupt it.--no-async-context-frame, tagging through CPED stops being possible and this would need its own field on promise reactions (a larger V8 patch).Testing
Built incrementally on the
custom-v24-pthreadtree (arm64, Docker), with qualialabs/node-fibers#9, all under--no-async-context-frame:fiber-await/test.json node-fibersjbaczuk/fiber-await-v24-stats): 11/11 with reuse on and off; dispatch off fails the expected 7, same as Node 24.21.0 for CORO_PTHREAD fibers (custom-v24-pthread): three node patches, no V8 changes #6's stock build.test/: all pass. znewsham's scenarios from node-fibers#7 (with the running fiber): 9/9, including the 100k park/resume test. meteor-promise suite with shared-packages#265: 15/15 (both promise implementations).--stress-scavenge=20and--stress-compaction.fiber-await/bench.js: fiberless awaits 0.03–0.04 us (stock Node 24.21.0 for CORO_PTHREAD fibers (custom-v24-pthread): three node patches, no V8 changes #6: 0.03), chained awaits in a fiber 0.10 us, I/O-style awaits ~28 us (the pthreadrun()+yield()floor is ~22 us), drains unchanged.jbaczuk/node-24-gdc-fiber-await, on top of qualia#56473): boots; a startup hook that awaits and then makes a sync Mongo call works on a hidden fiber; fiberless code still throwsCan't wait without a fiber.🤖 Generated with Claude Code