Skip to content

Conversation

@pentp
Copy link
Contributor

@pentp pentp commented May 31, 2025

Inspired by this comment: #116111 (comment)

Copilot AI review requested due to automatic review settings May 31, 2025 14:17
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 31, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 31, 2025
Copy link
Contributor

Copilot AI left a 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)

@teo-tsirpanis teo-tsirpanis added area-Extensions-FileSystem and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels May 31, 2025
@dotnet-policy-service
Copy link
Contributor

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

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@stephentoub
Copy link
Member

Thanks.

@stephentoub stephentoub merged commit 5fab56b into dotnet:main Jun 3, 2025
83 of 86 checks passed
@pentp pentp deleted the polling-wildcard branch June 3, 2025 10:33
@github-actions github-actions bot locked and limited conversation to collaborators Jul 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Extensions-FileSystem community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants