msbuild
msbuild copied to clipboard
adding a cache for FileMatcher regexes to avoid repeated allocations
Fixes #11872
Context
Adding a Regex Cache to FileMatcher to avoid repeated Regex creation.
Changes Made
FileMatcher.cs -> added a cache.
Testing
Existing tests.
Notes
I added a repro in the issue.
On an OrchardCore the cache size on a single process was: 46 for an incremental build 40 for Clean 46 for full build (in retrospect I should've expected that)
Also, there are already two unbounded caches in the same file and we only ever flush them if specifically demanded via BuildRequestDataFlags.ClearCachesAfterBuild so I think we're either already in trouble or mostly fine.
A question though: Since this is related to globbing, is there any relation to the MSBuildGlob.cs -> s_regexCache? (I found it due to the name being the same)
My take is that this unbounded cache is fine, given 46 items for Orchard. I can't imagine a build with a large number of unique glob expressions in XML.