-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Optimize file system enumeration pattern matching with specialized delegates #123041
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
Draft
Copilot
wants to merge
6
commits into
main
Choose a base branch
from
copilot/optimize-file-system-enumeration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+189
−23
Conversation
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
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-io |
…legates Co-authored-by: stephentoub <[email protected]>
Co-authored-by: stephentoub <[email protected]>
Copilot
AI
changed the title
[WIP] Optimize file system enumeration pattern matching
Optimize file system enumeration pattern matching with specialized delegates
Jan 9, 2026
stephentoub
reviewed
Jan 9, 2026
src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerableFactory.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerableFactory.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerableFactory.cs
Show resolved
Hide resolved
…, combine IsDirectory check with matcher Co-authored-by: stephentoub <[email protected]>
stephentoub
reviewed
Jan 9, 2026
src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerableFactory.cs
Outdated
Show resolved
Hide resolved
…in delegates Co-authored-by: stephentoub <[email protected]>
stephentoub
reviewed
Jan 9, 2026
src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerableFactory.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerableFactory.cs
Outdated
Show resolved
Hide resolved
…ds, entryType) tuple Co-authored-by: stephentoub <[email protected]>
Member
|
@EgorBot -amd -intel -arm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
File system enumeration was re-checking pattern types on every entry to determine if fast paths apply (
*literal→ EndsWith). This moves pattern analysis to enumerable creation time and creates specialized delegates upfront.Changes:
GetPredicate<T>that analyzes patterns once and returns optimizedFileSystemEnumerable<T>.FindPredicatedelegates:*→ always-true predicate (with IsDirectory/IsFile check)*literal→EndsWith(existing optimization, moved earlier)literal*→StartsWith(new)*literal*→Contains(new)SearchValues<char>(SimpleWildcards,ExtendedWildcards) to internal static readonly fields inFileSystemNamefor shared useexpressionin lambdas and compute span slices inline on each invocation to avoid string allocations and minimize capture overhead(useExtendedWildcards, entryType)tuple to return distinct delegates without capturing unnecessary variablesCustomer Impact
Performance improvement for file enumeration with common glob patterns. Each file entry now calls a simple string operation instead of re-evaluating pattern structure and potentially running the full matching algorithm.
Regression
No. This is a performance optimization.
Testing
literal*(StartsWith) and*literal*(Contains) patterns inFileSystemNameTests.csPatternTransformTests.csexercising actual file enumeration with optimized patternsRisk
Low. The optimization preserves existing behavior by falling back to full pattern matching for any pattern not matching the fast paths. All existing tests pass unchanged.
Package authoring no longer needed in .NET 9
IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.