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

avoid ReadFile syscall if we know that there is nothing to read from file #56387

Merged
merged 2 commits into from Jul 27, 2021

Conversation

adamsitnik
Copy link
Member

This can save us a single ReadFile sys-call for cases when we know that there is nothing to read from the file, which should happen once for every loop like this:

while (await fileStream.ReadAsync(userBuffer, cancellationToken) != 0)

The perf gain depends on the file size and the number of actual reads. For a small file where we read entire content with first call, we can save up to 10%.

@adamsitnik adamsitnik added this to the 6.0.0 milestone Jul 27, 2021
@adamsitnik adamsitnik added this to In progress in System.IO - FileStream via automation Jul 27, 2021
@ghost
Copy link

ghost commented Jul 27, 2021

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

This can save us a single ReadFile sys-call for cases when we know that there is nothing to read from the file, which should happen once for every loop like this:

while (await fileStream.ReadAsync(userBuffer, cancellationToken) != 0)

The perf gain depends on the file size and the number of actual reads. For a small file where we read entire content with first call, we can save up to 10%.

Author: adamsitnik
Assignees: -
Labels:

area-System.IO

Milestone: 6.0.0

System.IO - FileStream automation moved this from In progress to Reviewer approved Jul 27, 2021
Co-authored-by: Stephen Toub <stoub@microsoft.com>
@adamsitnik adamsitnik merged commit c81ca16 into dotnet:main Jul 27, 2021
System.IO - FileStream automation moved this from Reviewer approved to Done Jul 27, 2021
@adamsitnik adamsitnik deleted the avoidSyscallWhenNoContentToRead branch July 27, 2021 16:13
@dotnet dotnet locked as resolved and limited conversation to collaborators Aug 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants