Skip to content

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 requested a review from stephentoub July 27, 2021 13:55
@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

@adamsitnik adamsitnik merged commit c81ca16 into dotnet:main Jul 27, 2021
@adamsitnik adamsitnik deleted the avoidSyscallWhenNoContentToRead branch July 27, 2021 16:13
@ghost ghost 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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants