perf(ext/web): add write buffering for FsFile.writable streams#32676
Open
bartlomieju wants to merge 1 commit intomainfrom
Open
perf(ext/web): add write buffering for FsFile.writable streams#32676bartlomieju wants to merge 1 commit intomainfrom
bartlomieju wants to merge 1 commit intomainfrom
Conversation
Small buffer writes (e.g. 128 bytes) via `file.writable.getWriter().write()` were ~100x slower than Node.js because each write immediately dispatched a syscall through the async op machinery with zero buffering. Add an opt-in `bufferSize` option to `writableStreamForRid()` and enable it with a 64KB buffer for `FsFile.writable`. Small chunks are accumulated in a JS-side buffer and flushed when full or on close. Large chunks (>= bufferSize) bypass the buffer entirely. The highWaterMark and sizeAlgorithm are also adjusted to operate on byte length when buffering is enabled. Only FsFile writable streams are affected — network sockets, stdin, QUIC, and WebTransport streams remain unbuffered. Ref: #16667 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
writableStreamForRid()via a newbufferSizeoptionFsFile.writablestreams only — network sockets, stdin, QUIC, and WebTransport remain unbufferedclose(); large chunks (>= 64KB) bypass the bufferMotivation
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
writableStreamForRid(rid, autoClose, cfn, { bufferSize })— onlyFsFile.writablepasses itbufferSize > 0,highWaterMarkswitches to byte-based sizing instead of count-basedclose()flushes remaining buffer,abort()discards itTest plan
cargo test -p deno_runtimefile.writable.getWriter().write()close()flushes remaining buffered data🤖 Generated with Claude Code