We Ralph Wiggumed WebStreams to make them 10x faster
By Steven Van ·
The new fast-webstreams library speeds up Next.js server rendering and is being upstreamed into Node.js itself.
Vercel built a library called fast-webstreams that reimplements the WHATWG ReadableStream, WritableStream, and TransformStream APIs on top of Node.js's older, C++-backed streaming internals. The rewrite followed profiling of Next.js server rendering that found the overhead was in the streams themselves, not the application code running inside them: extra Promise allocations, per-chunk objects, and microtask queue hops that the WHATWG spec requires but a server doesn't need.
- Piping between fast streams: about 6,200 MB/s, roughly 10x native WebStreams and close to raw Node.js pipeline speed, achieved by collapsing a chain of pipeThrough/pipeTo calls into a single pipeline() call instead of running Promises per chunk.
- Chunk-by-chunk reads with reader.read(): about 12,400 MB/s, 3.7x faster than native, by resolving synchronously when data is already buffered instead of going through the microtask queue.
- The byte-stream pattern React Server Components use to stream Flight payloads: about 1,600 MB/s versus roughly 110 MB/s natively, a 14.6x gain, powered by a new array-based buffer called LiteReadable built to replace Node's Readable for this case.
The library also patches Response.prototype.body so fetch responses piped through several transforms, a common pattern when forwarding data from an upstream service through a rendering pipeline, get the same fast path. Vercel says this work is already being upstreamed into Node.js itself through a PR from Matteo Collina.
