-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
File::read_to_end's unexpected performance on Windows #110650
Copy link
Copy link
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.O-windowsOperating system: WindowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.O-windowsOperating system: WindowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
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 inbufVec's capacity, the longer the call takes—regardless of actually read bytes.With the above code, increasing
BUFFER_SIZEwill linearly increase the runtime ofread_to_end, even if we're always reading1024bytes.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_endwould 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