Writer.drain: coalesce 1-byte splat through a stack buffer#32
Merged
Conversation
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.
Owner
|
Nice, thanks. How did you run into this? |
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. |
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.
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.