-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
SafeFileHandle.ThreadPoolValueTaskSource made ligher by one field #113435
base: main
Are you sure you want to change the base?
Conversation
This is my first PR to the mighty |
Tagging subscribers to this area: @dotnet/area-system-io |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a performance optimization. Do you have any benchmark that shows this makes a difference?
Debug.Assert(_readScatterBuffers != null); | ||
result = RandomAccess.ReadScatterAtOffset(_fileHandle, _readScatterBuffers, _fileOffset); | ||
Debug.Assert(_buffers != null); | ||
result = RandomAccess.ReadScatterAtOffset(_fileHandle, Unsafe.As<IReadOnlyList<Memory<byte>>>(_buffers), _fileOffset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not ok to use Unsafe.As
just because of you can. In fact, we are working on eliminating Unsafe.As and similar uses to make the runtime core more secure by construction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearly, one cannot use it just like that. The reasoning was that the setting of the field is made only in one of two scatter/gather methods and this is aligned with setting the _operation
. In my opinion it's similar to the case in ValueTask
which also casts As according to the "type" held in another filed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could make a regular cast; the always-true type check will be dwarfed by the cost of the subsequent I/O operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced by the regular
Let me spin some tomorrow and share what it does. |
This PR combines gather/scatter fields in
SafeFileHandle.ThreadPoolValueTaskSource
into one. This saves one reference field inTPVTS
.