Reduce allocations in PollingWildCardChangeToken#116175
Merged
stephentoub merged 3 commits intodotnet:mainfrom Jun 3, 2025
Merged
Reduce allocations in PollingWildCardChangeToken#116175stephentoub merged 3 commits intodotnet:mainfrom
stephentoub merged 3 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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)
Contributor
|
Tagging subscribers to this area: @dotnet/area-extensions-filesystem |
stephentoub
reviewed
Jun 1, 2025
Member
|
Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Inspired by this comment: #116111 (comment)