Closed
Conversation
For every call to the read() function the internal buffer was copied into a new buffer (minus the bytes copied into the result buffer). When the internal buffer is large enough, this severely affects performance, especially when read_line() is used which calls read_byte() (which calls read()) for each read byte. For line oriented I/O this wasn't all that bad, because the internal buffers usually never were very big. The effect is much more visible once the buffer grows larger. Now we always first look into the internal buffer and copy as many bytes as possible (and desired) into the result buffer. If we need more, we call the socket read function and use the result as the new internal buffer, then continue to copy from the (new) internal buffer, and so on.
No need to allocate an additional vector. Instead directly push into the string.
Contributor
|
For future reference, you can aim pull requests at the incoming branch by clicking on the black box that says |
Contributor
Author
|
ok! |
Contributor
|
Thanks! Merged. |
Contributor
|
Doesn't the fn main() {
// old version
let b = ~[0xC3u8, 0xA5];
io::println(str::from_bytes(b)); // prints 'å'
// new version
let mut s = ~"";
str::push_char(&mut s,0xC3 as char);
str::push_char(&mut s,0xA5 as char);
io::println(s); // prints 'Ã¥'
} |
Contributor
|
@dbaupp Yes, you are right. I will add a test and revert. |
Contributor
Author
|
I think instead it would be save to do at the end |
RalfJung
added a commit
to RalfJung/rust
that referenced
this pull request
Oct 15, 2025
Automatic Rustup
RalfJung
added a commit
to RalfJung/rust
that referenced
this pull request
Oct 15, 2025
Automatic Rustup
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.
Please see especially the rewrite of TcpSocketBuf.read which fixes a performance bug.