Skip to content
Dashboard

We Ralph Wiggumed WebStreams to make them 10x faster

CTO, Vercel

Copy link to headingThe problem

Copy link to headingWhat we built

Copy link to headingWhen you pipe between fast streams: zero Promises

const source = new ReadableStream({
pull(controller) {
controller.enqueue(generateChunk());
}
});
const transform = new TransformStream({
transform(chunk, controller) {
controller.enqueue(process(chunk));
}
});
const sink = new WritableStream({
write(chunk) { consume(chunk); }
});
// Internally: single pipeline() call, zero promises per chunk
await source.pipeThrough(transform).pipeTo(sink);

Copy link to headingWhen you read chunk by chunk: synchronous resolution

const reader = stream.getReader();
while (true) {
const { value, done } = await reader.read();
if (done) break;
// When data is buffered, the await resolves immediately
// via Promise.resolve() — no microtask queue hop
processChunk(value);
}

Copy link to headingThe React Flight pattern: where the gap is largest

let ctrl;
const stream = new ReadableStream({
type: 'bytes',
start(c) { ctrl = c; }
});
// As React renders each component:
ctrl.enqueue(new Uint8Array(payload1));
ctrl.enqueue(new Uint8Array(payload2));
ctrl.close();

Copy link to headingFetch response bodies: streams you don't construct yourself

const upstream = await fetch('<https://api.example.com/data>');
// Pipe through transforms and forward as a new Response
const transformed = upstream.body
.pipeThrough(new TransformStream({ transform(chunk, ctrl) { /* ... */ ctrl.enqueue(chunk); } }))
.pipeThrough(new TransformStream({ transform(chunk, ctrl) { /* ... */ ctrl.enqueue(chunk); } }))
.pipeThrough(new TransformStream({ transform(chunk, ctrl) { /* ... */ ctrl.enqueue(chunk); } }));
return new Response(transformed);

Copy link to headingBenchmarks

Copy link to headingCore operations

Copy link to headingTransform chains

Copy link to headingByte streams

Copy link to headingResponse body patterns

Copy link to headingStream construction

Copy link to headingSpec compliance

Copy link to headingHow we are deploying this

import { patchGlobalWebStreams } from 'fast-webstreams';
patchGlobalWebStreams();
// globalThis.ReadableStream is now the fast implementation
// fetch() response bodies are automatically wrapped
// All downstream pipeThrough/pipeTo use fast paths

Copy link to headingThe right fix is upstream

Copy link to headingWhat we learned the hard way

Copy link to headingWe built most of fast-webstreams with AI

Copy link to headingTry it

Ready to deploy?