Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection: Don't double-buffer TCP stream #102

Merged
merged 1 commit into from
Jan 6, 2024

Conversation

mrkline
Copy link
Contributor

@mrkline mrkline commented Jan 6, 2024

UnsecuredStream doesn't need to be wrapped in a BufWriter since write_all() passes the entire buffer-to-send to the underlying TCP stream.1 And it doesn't need to be wrapped in a BufReader since HttpStreamBytes (in response.rs) wraps the whole HttpStream in a BufReader. Both of these cases cause us to use a little extra memory and copy bytes twice when we only need to copy once.

UnsecuredStream doesn't need to be wrapped in a BufWriter since
write_all() passes the entire buffer-to-send until the OS has
written it out.[1] And it doesn't need to be wrapped in a BufReader
since HttpStreamBytes (in response.rs) wraps the whole HttpStream
in a BufReader. Both of these cases cause us to use a little
extra memory and copy bytes twice when we only need to copy once.

[1]: https://doc.rust-lang.org/src/std/io/mod.rs.html#1620-1635
@neonmoe
Copy link
Owner

neonmoe commented Jan 6, 2024

Good points! Makes the code cleaner as well. Thanks for the PR, I appreciate it :)

@neonmoe neonmoe merged commit 4d40862 into neonmoe:master Jan 6, 2024
5 checks passed
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