deno
4ba47aaf - perf(ext/web): add write buffering for FsFile.writable streams (#32676)

Commit
250 days ago
perf(ext/web): add write buffering for FsFile.writable streams (#32676) ## Summary - Add opt-in write buffering to `writableStreamForRid()` via a new `bufferSize` option - Enable 64KB buffering for `FsFile.writable` streams only — network sockets, stdin, QUIC, and WebTransport remain unbuffered - Small chunks are accumulated in a JS-side buffer and flushed when full or on `close()`; large chunks (>= 64KB) bypass the buffer ## Motivation Closes #16667 Writing small buffers (128 bytes) via `file.writable.getWriter().write()` is ~100x slower than Node.js. The root cause is that every small write goes through: JS promise machinery → async op dispatch → task queue permit → spawn_blocking → syscall, with zero buffering. With this change, 100K writes of 128 bytes drops from ~1.6s to ~0.06s (debug build). ## Design - Buffering is **opt-in** via `writableStreamForRid(rid, autoClose, cfn, { bufferSize })` — only `FsFile.writable` passes it - When `bufferSize > 0`, `highWaterMark` switches to byte-based sizing instead of count-based - Buffer is lazily allocated on first small write - `close()` flushes remaining buffer, `abort()` discards it Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Author
Parents
Loading