Bun.ArrayBufferSink — streaming buffer builder for SSR
Bun.ArrayBufferSink lets you accumulate bytes from many writes into a single ArrayBuffer or stream them out, with fewer intermediate allocations than Uint8Ar…
Summary
Bun.ArrayBufferSink lets you accumulate bytes from many writes into a single ArrayBuffer or stream them out, with fewer intermediate allocations than Uint8Array concatenation.
Why backlog
Current SSR uses renderToReadableStream from React and pipes through to Response. No measured benefit yet — we don't have profiling that says the stream path is allocation-bound.
Trigger to promote to draft
- SSR profiling (e.g. heap snapshots under load) shows the stream → Response path is GC-bound, OR
- An HTML compressor / minifier plugin wants a write-sink it can flush incrementally.
Bun-unique classification
Bun-only — Node has no equivalent streaming buffer builder. Buffer.concat is eager; writable streams are higher-level.
Open questions when promoted
- Does this replace
ReadableStreamend-to-end, or only the inner accumulation buffer behind a stream wrapper? - Edge adapter (no Bun) needs a fallback path — likely
Uint8Arrayconcat with a worse allocation profile.