-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Reduce allocations in PollingWildCardChangeToken #116175
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
Conversation
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.
Pull Request Overview
This PR aims to reduce allocations in PollingWildCardChangeToken by modifying how timestamps and hash computations are handled.
- Changed _lastScanTimeUtc from a nullable DateTime to a non-nullable DateTime with a Ticks check as a sentinel value.
- Optimized ComputeHash by using MemoryMarshal for zero-allocation conversions in the NET build.
- Updated hash assignment logic and simplified the HasChanged property.
Comments suppressed due to low confidence (3)
src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PollingWildCardChangeToken.cs:141
- Using the conditional assignment (??=) here means that once _previousHash is set, it will never update even if file contents change. Please verify that this behavior is intended for correct change tracking.
_previousHash ??= currentHash;
src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PollingWildCardChangeToken.cs:179
- Ensure that using MemoryMarshal.AsBytes on an array containing lastChangedUtc produces a consistent byte representation compared to using BinaryPrimitives.WriteInt64LittleEndian in the non-NET branch.
sha256.AppendData(MemoryMarshal.AsBytes([lastChangedUtc]));
src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PollingWildCardChangeToken.cs:125
- [nitpick] Using _lastScanTimeUtc.Ticks != 0 as a sentinel for uninitialized state is clear, but please confirm that treating DateTime.MinValue as an appropriate default works correctly with all expected file timestamps.
if (_lastScanTimeUtc.Ticks != 0 && _lastScanTimeUtc < lastWriteTimeUtc)
|
Tagging subscribers to this area: @dotnet/area-extensions-filesystem |
src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PollingWildCardChangeToken.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PollingWildCardChangeToken.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PollingWildCardChangeToken.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PollingWildCardChangeToken.cs
Show resolved
Hide resolved
stephentoub
left a comment
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.
Thanks.
|
Thanks. |
Inspired by this comment: #116111 (comment)