WASI Preview 2 uses the WASM Component Model, which relies heavily on resources (conceptually objects). Interacting with these resources (e.g., setting an HTTP header) requires frequent calls from the WASM environment into the JavaScript host.
In a VS Code environment, this creates significant overhead because:
- Extension Host Isolation: WASM code must run in a separate worker to avoid blocking the VS Code extension host.
- Context Switching: Accessing the VS Code API requires a message-passing cycle between the WASM worker and the extension host worker.
- Multi-threading Constraints: While WASM threads share a memory region, JavaScript workers (which back WASM threads) have independent heaps. Sharing host-side state (like a stream or a resource) between workers requires expensive synchronization or data copying.
Performance Gap: Retrieving a number via the current context-switching mechanism can be up to 3000x slower than using SharedArrayBuffers in a single thread (e.g., ~30 seconds for 1 million calls vs ~10ms).