UwsResponse._write() sends each chunk to uWS individually instead of using the existing writeChunk() batching system. For readable.pipe(res) with many small chunks (e.g., 4KB from fs.createReadStream), this results in hundreds of uWS.write() syscalls instead of ~4-16 batched writes.
Root cause: _write() calls streamChunk() directly:
_write(chunk, encoding, callback) {
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding);
this.streamChunk(buffer, this.contentLengthTotal)
.then(() => callback())
.catch((error) => callback(error));
}
streamChunk() calls this.atomic(() => this.uwsRes.write(buffer)) per chunk with no batching.
Existing batching: writeChunk() already implements intelligent batching:
- Accumulates chunks in
pendingChunks[]
- Flushes when
HIGH_WATERMARK (128KB) reached
- Flushes on
FLUSH_INTERVAL (50ms) timeout
- First chunk sent immediately for low latency
UwsResponse._write()sends each chunk to uWS individually instead of using the existingwriteChunk()batching system. Forreadable.pipe(res)with many small chunks (e.g., 4KB fromfs.createReadStream), this results in hundreds ofuWS.write()syscalls instead of ~4-16 batched writes.Root cause:
_write()callsstreamChunk()directly:streamChunk()callsthis.atomic(() => this.uwsRes.write(buffer))per chunk with no batching.Existing batching:
writeChunk()already implements intelligent batching:pendingChunks[]HIGH_WATERMARK(128KB) reachedFLUSH_INTERVAL(50ms) timeout