DEV Community

How to achieve zero-copy streaming from hyper and h3-quinn into a Wasmtime Wasm component via wasi:http?

Background

I am currently building a high-performance API gateway that integrates business logic components-implemented via WASI and running within Wasmtime-as HTTP/TCP/QUIC handlers. I am exploring the best design approach to achieve a zero-copy data path from the upstream network layer-specifically hyper for HTTP/1.x and HTTP/2, and h3-quinn (based on Quinn) for HTTP/3-to the wasi:http guest environment.

Given that:

  • hyper and h3-quinn each manage their own internal buffer pools (e.g., bytes::Bytes), asynchronous read/write streams, and frame decoders.
  • Wasmtime's wasmtime-wasi-http implements the wasi:http (WASIp2) specification, which relies on resource types such as InputStream and OutputStream.

I aim to minimize memory copying and CPU overhead when passing large request bodies or streaming responses across the sandbox boundary.

For those experienced with bridging I/O between the host and guest in Wasmtime, I have a few architectural questions:

Buffer ownership and memory mapping

How can host-side bytes::Bytes (from hyper or h3-quinn) be mapped or bridged into Wasm linear memory (and vice versa) without requiring a CPU-based memcpy? Does Wasmtime's resource streaming support direct memory views, or are we essentially limited to copying data chunks via guest memory pointers?

Adapting stream abstractions

hyper uses http_body_util::combinators / http_body::Body, h3 uses its own stream primitives, while wasi:http uses wasi:io/streams. What is the idiomatic way to efficiently adapt these asynchronous streams on the host side (i.e., within the wasmtime-wasi-http handler implementation) without blocking the tokio runtime?

Backpressure propagation

How can backpressure signals be correctly propagated from the Wasm guest (e.g., when the guest's InputStream is consuming data slowly) all the way back to the Quinn congestion controller or Hyper connection pool, thereby avoiding unbounded buffering on the host side?

If anyone has built similar high-performance gateway, proxy, or service mesh architectures using Wasmtime and wasi:http, I would greatly appreciate it if you could share architectural patterns, code references, or insights regarding current limitations. Many thanks!

Top comments (0)

Comments

No comments yet. Start the discussion.