Repository navigation
[FileSystemGlobbing] Use the compiled Touki matcher on .NET 8+ - #132192
Draft
JeremyKuhne wants to merge 1 commit into
Draft
JeremyKuhne wants to merge 1 commit into
JeremyKuhne wants to merge 1 commit into
Conversation
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-extensions-filesystem |
Member
Author
Contributor
There was a problem hiding this comment.
Pull request overview
Introduces a new, internal Touki-derived compiled glob matching engine for Microsoft.Extensions.FileSystemGlobbing.Matcher on .NET 8+ (via a new net8.0 asset), while retaining the legacy matcher for downlevel TFMs and unsupported cases. The change also adds a FileSystemEnumerator-based fast path when executing against the exact built-in DirectoryInfoWrapper type.
Changes:
- Add a
net8.0target and conditional compilation to enable a Touki-backed matching/execution path on .NET 8+. - Implement internal Touki-based compiled pattern/matcher planning and a
FileSystemEnumerator-based traversal fast path. - Expand test coverage to validate parity and key semantics (ordered rules, stems, fallback cases, wrapper behavior).
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| THIRD-PARTY-NOTICES.TXT | Adds Touki license notice for the imported internal subset. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/PatternMatchingTests.cs | Adds parity/oracle tests and additional behavioral coverage for fallback and edge cases. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/OrderedPatternMatchingTests.cs | Adds a regression test for ordered include/exclude “winner” stem behavior. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/FunctionalTests.cs | Adds functional tests for wrapper fast path selection and direct exclusion pruning behavior. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Microsoft.Extensions.FileSystemGlobbing.csproj | Adds explicit net8.0 targeting and conditional compilation/items for Touki-backed implementation. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/ref/Microsoft.Extensions.FileSystemGlobbing.csproj | Adds explicit net8.0 targeting for the ref project to ensure correct asset selection. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Matcher.cs | Adds cached internal Touki plan execution path on .NET 8+ with fallback to legacy behavior. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/ToukiPattern.cs | Introduces lazy compilation + stem calculation wrapper around legacy patterns for Touki strategies. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/ToukiMatcherContext.cs | Adds the Touki execution context, plan creation, and FileSystemEnumerator traversal fast paths. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/ExclusionWinsPatternMatcher.cs | Adds Touki-style exclusion-wins include/exclude evaluation returning the winning include pattern. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/OrderedPatternMatcher.cs | Adds Touki-style ordered rule evaluation returning the latest winning include pattern. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/AnyGlobStrategy.cs | Adds compiled strategy for matching any input. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/CompiledGlobStrategy.cs | Adds a general-purpose compiled matcher with NFA-style backtracking and tail anchoring. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/CompiledGlobStrategy.BacktrackState.cs | Adds internal backtracking state container for the compiled matcher. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/ContainsGlobStrategy.cs | Adds compiled strategy for *needle* segment matching. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/GlobCompiler.cs | Adds the internal entry point for compiling patterns into strategies. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/GlobCompiler.Factory.cs | Adds the pattern compiler/factory and bytecode encoding logic. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/GlobCompiler.Factory.LiteralCursor.cs | Adds helper state used by the compiler to rewrite trailing literal segments during encoding. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/GlobOpCodes.cs | Adds opcode definitions for the compiler’s bytecode-in-a-string encoding. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/GlobStarFileNameStrategy.cs | Adds specialized strategy for **/<segment> shapes to bypass the general bytecode matcher. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/GlobStrategy.cs | Adds the strategy abstraction used by compiled patterns. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/LiteralDirectoryPathStrategy.cs | Adds a strategy for matching a fixed directory prefix with a segment matcher. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/LiteralGlobStrategy.cs | Adds a strategy for exact literal matching (including split-span comparisons). |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/PrefixGlobStrategy.cs | Adds a strategy for prefix* matching. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/PrefixSuffixGlobStrategy.cs | Adds a strategy for prefix*suffix matching. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/RecursiveDirectoryPathStrategy.cs | Adds a strategy for matching a directory name recursively within a path prefix. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/RootFileNameStrategy.cs | Adds root-scoping strategy wrapper for path-unaware patterns. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/Io/Globbing/SuffixGlobStrategy.cs | Adds a strategy for *suffix matching. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/Touki/GlobalUsings.cs | Adds Touki-internal global using directives for the imported subset. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/PatternContexts/PatternContextLinear.cs | Adds a conditional TrackStem toggle to avoid stem tracking overhead on Touki paths. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/PatternContexts/PatternContextRagged.cs | Adds a conditional TrackStem toggle to avoid stem tracking overhead on Touki paths. |
| src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Abstractions/DirectoryInfoWrapper.cs | Adds an internal accessor to the wrapped DirectoryInfo for the fast path. |
Comment on lines
+12
to
+16
| <PropertyGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp' and $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))"> | ||
| <UseToukiGlobbing>true</UseToukiGlobbing> | ||
| <DefineConstants>$(DefineConstants);USE_TOUKI_GLOBBING</DefineConstants> | ||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
| </PropertyGroup> |
Comment on lines
+87
to
+105
| private GlobStrategy? GetStrategy() | ||
| { | ||
| if (Volatile.Read(ref _compileAttempted)) | ||
| { | ||
| return _strategy; | ||
| } | ||
|
|
||
| lock (this) | ||
| { | ||
| if (!_compileAttempted) | ||
| { | ||
| GlobCompiler.TryCompile( | ||
| GetCompiledPattern(_legacyPattern), | ||
| _ignoreCase, | ||
| out _strategy); | ||
| Volatile.Write(ref _compileAttempted, true); | ||
| } | ||
| } | ||
|
|
Contributor
|
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
This branch has not been deployed
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.
Summary
This change uses a focused, internal subset of Touki's compiled glob matcher for
Microsoft.Extensions.FileSystemGlobbing.Matcheron .NET 8 and later. It also adds aFileSystemEnumeratorfast path for the exact built-inDirectoryInfoWrappertype.The existing implementation remains in place for
netstandard2.0, .NET Framework, custom and derived directory wrappers, unsupported comparison modes, and patterns the focused compiler cannot represent.No public API or package dependency is added. The reference API source is unchanged.
Relationship To The System.IO Globbing Proposal
This is an optimization of the existing FileSystemGlobbing API, not an implementation of #132060. That proposal remains open and is not API-approved.
Current Touki models the proposal's separation between an immutable reusable matcher definition and independently owned root-bound sessions. This adaptation uses the same lifetime split internally:
ToukiMatcherPlanToukiMatcherContextperExecuteToukiPatternGlobCompilerThe proposed
IFileSystemMatchercomposition API returns only a Boolean file result. FileSystemGlobbing must additionally identify the winning include to produceFilePatternMatch.Stem. The local exclusion-wins and ordered matchers therefore return that winner without evaluating the pattern twice.Proposal-only types such as
GlobSpecification,IFileSystemMatcher,DirectoryMatchType, andFileSystemPathEnumeratorare deliberately not imported or exposed here. Adding them would couple this package to an unapproved public design and add unused code.The focused port originated from Touki commit
74f6739ce8e70b760814e792c79a83fd5065c9d7and was revalidated against current Touki256c9b73c9d9e1c138b4b1a54a639342b7cc851c, including the FileSystemGlobbing parity work in JeremyKuhne/touki#259.Constraints Of The Existing API
The existing surface necessarily retains work that a purpose-built API can avoid:
PatternBuilderremains the validation and normalization authority so exception timing, accepted syntax, parent traversal, and legacy edge cases do not change.DirectoryInfoBaseis a public extensibility point. Only the exact built-in wrapper can use the physicalFileSystemEnumeratorpath; derived and custom implementations must continue through virtual enumeration.Matcheris a mutable include/exclude builder. Pattern additions invalidate the cached plan, and each execution creates fresh traversal state.PatternMatchingResult, relative paths,FilePatternMatchvalues, and stems.These constraints are why the improvement here is smaller than Touki's direct compiled-matcher results: the inner predicate becomes inexpensive, but the public API still owns traversal compatibility and result construction.
Adapted Performance Win
The unchanged public API benchmark shows lower allocation and flat-to-faster execution across the representative scenarios:
*.cshit**/*.cs, deep inputFor a 1,174-file physical Touki checkout, the specialized wrapper and retained overhead reductions changed the adapter's construct-and-execute path from 3.325 ms / 980.48 KB to 2.687 ms / 210.12 KB. A precompiled matcher measured 2.633 ms / 202.29 KB.
These local Windows BenchmarkDotNet runs are short and sequential, so timing changes should be treated directionally. The allocation reductions are stable.
Headroom In A Purpose-Built API
The proposed API can expose compiled span matching directly and stream canonical paths from a matcher-aware enumerator. It does not need to build a virtual file system, calculate FSG stems, retain legacy pattern contexts, or materialize a
PatternMatchingResult.Current Touki measurements cited in #132060 show the difference in achievable scope:
GlobSpecification.IsMatchcases run in roughly 8.5-75 ns with zero managed allocation, 13-89x faster than the closest publicMatcher.Matchscenarios. The operations return different result shapes, so this is not the expected speedup for this PR.This PR captures the compatible win available behind the current API. The API proposal represents the additional headroom available when callers can opt into an immutable compiled matcher and a purpose-built streaming enumeration contract.
Compatibility And Packaging
The source and reference projects gain an explicit
net8.0target. Without it, .NET 8 and .NET 9 consumers would select thenetstandard2.0package asset and remain on the legacy engine.netstandard2.0net8.0assetnet8.0assetAll imported types are internal. The package contains no
Microsoft.IO.Redistdependency. The pinned source and MIT license are recorded in source headers andTHIRD-PARTY-NOTICES.TXT.Compatibility coverage includes:
Validation
build.cmd clr+libs -rc release.net11.0: 626 passed, 0 failed.net481: 626 passed, 0 failed.net8.0asset and validated matching, stems, and internal-only Touki metadata.net8.0asset.net8.0,net10.0,net11.0,netstandard2.0, andnet462; no new dependency groups.git diff --check, imported-source whitespace checks, and final independent Extensions review passed.The current runtime test infrastructure cannot restore this test project for net8 because its current xUnit assertion package targets net10. The complete modern suite therefore runs on net11, while isolated consumers validate net8 and net9 package selection.
Follow-Up Validation
Note
This pull request description was drafted with GitHub Copilot assistance.