Repository navigation
perf(api): opt in to host interrupt registration - #7178
syrusakbary wants to merge 3 commits into
Conversation
Committed by Codex (AI agent) on behalf of the user.
There was a problem hiding this comment.
🟡 Changes recommended
A critical nested-call interruption bug leaves suspended async imports without a cached interrupt flag or waker, preventing interruption from waking or terminating the call while the host future remains pending.
1 open issue
What changed in this PR
This PR makes native host interruption opt-in per store, reducing overhead for ordinary Wasm calls while integrating interruption with VM entry and async suspension.
Changes:
- Enable interruption through
Store::interrupter()and skip registration for plain calls. - Associate interrupt handling with the active Wasm trap context and preserve state across async suspension.
- Add coverage for opt-in behavior, module starts, nested stores, waker replacement, and cancellation.
| File | Description |
|---|---|
lib/vm/src/trap/traphandlers.rs |
Adds interruptible trap contexts and saved async trap state. |
lib/vm/src/trap/mod.rs |
Adds a trampoline entry with optional store interruption. |
lib/vm/src/store.rs |
Tracks per-store interruption opt-in. |
lib/vm/src/interrupt_registry/unix.rs |
Refactors registrations and signal-target tracking. |
lib/vm/src/interrupt_registry/mod.rs |
Gives guards direct access to interrupt flags. |
lib/vm/src/instance/mod.rs |
Applies store opt-in to module start execution. |
lib/api/tests/interrupt.rs |
Tests plain calls, module starts, and nested-store isolation. |
lib/api/tests/interrupt_async.rs |
Tests async opt-in, waker replacement, and cross-store cancellation. |
lib/api/src/entities/store/obj.rs |
Enables interruption when creating a store handle. |
lib/api/src/entities/store/mod.rs |
Documents the public opt-in behavior. |
lib/api/src/backend/sys/entities/store/mod.rs |
Clarifies low-level handles and gates async notifications. |
lib/api/src/backend/sys/entities/module.rs |
Removes module-level interrupt registration. |
lib/api/src/backend/sys/entities/function/typed.rs |
Routes typed calls through optional interruptible entry. |
lib/api/src/backend/sys/entities/function/mod.rs |
Updates dynamic entry and host-return interrupt checks. |
lib/api/src/backend/sys/async_runtime.rs |
Makes interrupt bookkeeping conditional and preserves suspended trap state. |
Review effort: Balanced
| if self.flag.is_none() | ||
| && let Some(registration) = &self.waker | ||
| { | ||
| // The VM registration stays live on the suspended stack. | ||
| self.flag = interrupt_registry::interrupt_flag(registration.store); |
Committed by Codex (AI agent) on behalf of the user.
Committed by Codex (AI agent) on behalf of the user.
Interesting - based on the included benchmarks (#7152), with the #7165 change included, I couldn't see any performance difference between That said, I would like to see the mentioned benchmarks being included into the |

Description
Add
InterruptCallWrapperfor synchronous native calls. Like the asyncify wrapper from #7151, it uses the existingCallWrapperAPI and composes with another wrapper. Acquiring anInterruptergives the caller a signal handle. The wrapper enables interrupt registration for each invocation, including retries made by an inner wrapper.Keep the wrapper, interrupter, registry, SIGUSR1 handler, and deferred host-return check in
lib/api/src/interrupt.rs. The native host trampolines callInterruptCallWrapper::finish_host_invocationbefore returning to Wasm. A pending interrupt traps before guest execution resumes. Plain synchronous calls bypass interrupt registration and their host imports skip the registry lookup. The VM exposes an opaque invocation token and generic signal-to-trap recovery. This keeps a signal for an outer store from trapping a nested call into a different store.Module start runs through
Instance::new, outside the function wrapper, and is now plain. The async runtime and tests use the upstream waker and polling behavior. The existing async coroutine enters the native function through a private entry point to retain its interrupt registration while suspended.Synchronous benchmarks
Seven interleaved release runs on an Apple M5 Max (arm64), macOS 27.0, and Rust 1.99.1, using Singlepass and
experimental-host-interruptin both builds. The baseline is9529d5b2883, which includes #7165. Times are medians. Export lookup and wrapper construction were outside the timed loop. The baseline registers interrupts on ordinary entry. The updated interruptible case usescall_wrappedwith a prebuiltInterruptCallWrapper. The callback loop runs 100,000 host imports per guest entry and reports time per callback.The feature-disabled typed-add control was 28.25 ns before and 29.17 ns after. All five non-interruptible entry cases improved in all seven paired runs, and the interruptible typed add slowed in all seven. The callback loop timing ranges overlapped.
Verification
experimental-host-interruptandexperimental-async. New coverage includes passive handles, wrapper composition and retries, wrong-store rejection, module start, nested stores, and deferred interruption before the guest resumes.make lintrequires additional dependencies unavailable in the offline Cargo cache.