msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

adding a cache for FileMatcher regexes to avoid repeated allocations

Open SimaTian opened this issue 6 months ago • 3 comments

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

SimaTian avatar May 30 '25 08:05 SimaTian

I added a repro in the issue.

KirillOsenkov avatar May 31 '25 00:05 KirillOsenkov

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)

SimaTian avatar Jun 10 '25 12:06 SimaTian

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.

KirillOsenkov avatar Jun 10 '25 22:06 KirillOsenkov