coverlet-coverage / coverlet

Cross platform code coverage for .NET
MIT License
2.99k stars 386 forks source link

Cache the regexes used in InstrumentationHelper #1693

Open xPaw opened 2 months ago

xPaw commented 2 months ago

See #1689 for discussion. Currently for every invocation of these functions, a new Regex instance is created which is wasteful.

A quick fix that should work would be using static Regex.IsMatch which caches them internally (up to 15 by default, so Regex.CacheSize may need to be tweaked).

Specifically IsValidFilterExpression, IsLocalMethod, IsTypeFilterMatch. The first two methods even have constant regex patterns.