Conversation
getGlobalFunc, typeKeyToIndex, registerFunc, withNewScope and the Wasm function factory took a pooled call stack and only returned it on the success path. A TVM error raised inside the call left the stack unrecycled, so the next call allocated a fresh one and the old buffer stayed alive with the instance. Return the stack in a finally block.
Large byte arguments currently grow the reusable PackedFunc call stack, so one large call permanently raises its capacity. Keep byte payloads out of the reusable stack once it reaches a 64 KiB soft limit, and place larger payloads in per-call Wasm allocations. Keep those allocations with the prepared frame through Asyncify suspension and release them when the call finishes or fails. Record offsets for Wasm-backed views before an allocation can grow linear memory and detach them.
Asyncify can suspend a prepared call after the JavaScript wrapper has been disposed through another alias. Take an extra reference on the PackedFunc when the call first unwinds and release it with the frame, so the rewound call still has a live callee. Synchronous calls do not take the reference. Release the retained handle with the frame, including when cleanup fails.
akaashrp
force-pushed
the
memory/05-transient-ffi-bytes
branch
from
September 30, 2026 07:16
f11d8b0 to
079fc38
Compare
This branch has not been deployed
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.
Three lifetime problems in the packed-call path of the web runtime.
In a Node microbenchmark a synchronous call with one int argument goes from 123 ns to about 165 ns, and 1 MiB byte arguments are 15 percent faster because they no longer grow the stack. Tests cover byte arguments across the soft limit, Wasm views that detach during a call, alias disposal during an Asyncify call, and frame cleanup that throws.