feat(vm): persistent worker reuse and synchronous proxy gas cost - #224
Open
jaspersagent wants to merge 2 commits into
Open
feat(vm): persistent worker reuse and synchronous proxy gas cost#224jaspersagent wants to merge 2 commits into
jaspersagent wants to merge 2 commits into
Conversation
A passed-in Worker can now be reused across sequential callVm calls: all message traffic is scoped by a per-call process id (nonce-suffixed so identical call data never collides), listeners detach when a call settles, and only internally spawned workers are terminated. The worker keeps a local WasmModuleCache since the host's instance does not survive structured clone, host-call Atomics waits carry a configurable timeout so a dead host cannot wedge the worker thread forever, and results synthesized from worker error/exit are flagged with crashed so pools can distinguish a dead worker from a non-zero program exit.
Adapters with a flat fee model can implement the optional getProxyHttpFetchGasCostSync to resolve the proxy gas cost without a host action. In the in-process mode every host action aborts and replays the wasm from the start, so answering synchronously removes one full execution per proxy fetch. Returning undefined falls back to the async host action, and worker (Atomics) mode is unaffected since host actions never abort there.
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.
Disclaimer: All numbers mentioned are just my local machine, I'm sure we'll get significantly better / different numbers on our production machines.
Makes the existing Atomics worker mode usable as a persistent single-execution engine. Previously callVm assumed a one-shot worker: listeners were never removed, messages carried no call identity, and a passed-in worker was terminated on completion, so consumers wanting to avoid the in-process abort-and-replay cost (3 wasm executions per proxy_http_fetch) had to pay a worker spawn per call instead. Reusing one worker per thread brings a measured 102ms to 17ms p50 per data request in the seda-candles executer under production-shaped load. All message traffic is now scoped by a nonce-suffixed process id, listeners detach on settle, the worker keeps a thread-local WasmModuleCache (the host's instance does not survive structured clone), Atomics waits carry a configurable hostCallTimeoutMs so a dead host cannot wedge the worker forever, and crash-synthesized results are flagged so pool implementations can fail over. A second commit adds an optional getProxyHttpFetchGasCostSync adapter hook so flat-fee adapters skip one abort-and-replay execution in the in-process mode; both changes are additive and the in-process replay path is byte-for-byte unchanged for adapters that opt out.