Skip to content

Writer.drain: coalesce 1-byte splat through a stack buffer#32

Merged
ianic merged 1 commit into
ianic:mainfrom
marler8997:updateSplat
May 6, 2026
Merged

Writer.drain: coalesce 1-byte splat through a stack buffer#32
ianic merged 1 commit into
ianic:mainfrom
marler8997:updateSplat

Conversation

@marler8997

Copy link
Copy Markdown
Contributor

Each call to Connection.writeAll emits a fresh TLS record (header + AEAD nonce + auth tag), so the previous loop (one writeAll per splat repetition) produced one record per byte for the common 1-byte pattern case. A 1 MiB splat became one million tiny records which is roughly three orders of magnitude slower than necessary.

This change switches on pattern.len to handle the 1-byte case which mirrors std.Io.Writer's Hashing and Allocating drains.

Each call to Connection.writeAll emits a fresh TLS record (header +
AEAD nonce + auth tag), so the previous loop (one writeAll per
splat repetition) produced one record per byte for the common
1-byte pattern case. A 1 MiB splat became one million tiny records which
is roughly three orders of magnitude slower than necessary.

This change switches on pattern.len to handle the 1-byte case
which mirrors std.Io.Writer's Hashing and Allocating drains.
@ianic ianic merged commit 819ae16 into ianic:main May 6, 2026
1 check passed
@ianic

ianic commented May 6, 2026

Copy link
Copy Markdown
Owner

Nice, thanks.

How did you run into this?

@marler8997

Copy link
Copy Markdown
Contributor Author

Was using this to spin up a small https server to stress test an http client (for Tuple). Was using splatByteAll to write some of the server responses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants