-
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
base: main
Are you sure you want to change the base?
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-io |
…legates Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
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
Outdated
Show resolved
Hide resolved
…, combine IsDirectory check with matcher Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerableFactory.cs
Outdated
Show resolved
Hide resolved
…in delegates Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
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 <2642209+stephentoub@users.noreply.github.com>
|
@EgorBot -amd -intel -arm |
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Added in 539b9a2. Literal patterns (no wildcards, no escape characters) now use a simple |
src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerableFactory.cs
Outdated
Show resolved
Hide resolved
|
@EgorBot -amd -intel -arm |
...libraries/System.Runtime/tests/System.IO.FileSystem.Tests/Enumeration/FileSystemNameTests.cs
Show resolved
Hide resolved
… default Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
...braries/System.Runtime/tests/System.IO.FileSystem.Tests/Enumeration/PatternTransformTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
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/FileSystemName.cs
Outdated
Show resolved
Hide resolved
…elds to s_camelCase Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
|
@EgorBot -amd -intel -arm |
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→Equalsfor exact filename matching (e.g., "log.txt" across directory hierarchies)*literal→EndsWith(existing optimization, moved earlier)literal*→StartsWith*literal*→Containsprefix*suffix→StartsWith+EndsWithwith minimum length checkSearchValues<char>(s_simpleWildcards,s_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 variables(startsWithStar, endsWithStar)tuple for cleaner code organizationCustomer 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
FileSystemNameTests.csfor literal patterns,literal*(StartsWith),*literal*(Contains), andprefix*suffixpatternsPatternTransformTests.csthat reference existingSimpleMatchDataandWin32MatchDatatheory data fromFileSystemNameTests, creating actual files and validating enumeration results for each pattern type through the full enumeration path including the optimized delegatesRisk
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.
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.