-
Notifications
You must be signed in to change notification settings - Fork 13.3k
File::read_to_end
's unexpected performance on Windows
#110650
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
As Reddit user John T. Erickson pointed out, this is also reproducible with C, so the issue probably lies with Windows. Still, maybe a clever workaround on Rust's side would be preferable? |
Hm, it probably doesn't have to be that clever. The internal |
…ChrisDenton delay uncapping the max_read_size in File::read_to_end In rust-lang#130600 (comment) I realized that we're likely still passing too-large buffers to the OS, at least once at the end. Previous issues and PRs: * rust-lang#110650 * rust-lang#110655 * rust-lang#118222 r? ChrisDenton
…ChrisDenton delay uncapping the max_read_size in File::read_to_end In rust-lang#130600 (comment) I realized that we're likely still passing too-large buffers to the OS, at least once at the end. Previous issues and PRs: * rust-lang#110650 * rust-lang#110655 * rust-lang#118222 r? ChrisDenton
…ChrisDenton delay uncapping the max_read_size in File::read_to_end In rust-lang#130600 (comment) I realized that we're likely still passing too-large buffers to the OS, at least once at the end. Previous issues and PRs: * rust-lang#110650 * rust-lang#110655 * rust-lang#118222 r? ChrisDenton
Rollup merge of rust-lang#130670 - the8472:read-to-end-heuristics, r=ChrisDenton delay uncapping the max_read_size in File::read_to_end In rust-lang#130600 (comment) I realized that we're likely still passing too-large buffers to the OS, at least once at the end. Previous issues and PRs: * rust-lang#110650 * rust-lang#110655 * rust-lang#118222 r? ChrisDenton
I came across an unexpected performance degradation on Windows when using
File::read_to_end(&mut self, buf: &mut Vec<u8>)
: the larger the passed inbuf
Vec
's capacity, the longer the call takes—regardless of actually read bytes.With the above code, increasing
BUFFER_SIZE
will linearly increase the runtime ofread_to_end
, even if we're always reading1024
bytes.This doesn't seem to happen on other OSes. At first I assumed I was doing something wrong, but with help from folks at StackOverflow we realized most of the time is spent in
NtReadFile
. One can get around this by usingfile.read_exact(&mut buffer[0..len])
orfile.take(len).read_to_end()
instead.I don't know what the implication of querying for the file size and using it in
read_to_end
would have, or if it'd be possible to get around this another way, but I assume at the very worst we could have a warning in the documentation about this.Meta
The text was updated successfully, but these errors were encountered: