Skip to content
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

Regex.IsMatch(string, string) inside NamingSettings.ctor is causing 15.1% allocations #3629

Closed
ninedan opened this issue Apr 6, 2023 · 3 comments · Fixed by #3639
Closed
Labels

Comments

@ninedan
Copy link
Contributor

ninedan commented Apr 6, 2023

Building a large project, found Regex.IsMatch(string, string) inside NamingSettings.ctor is causing 15.1% allocations, mostly due to constructing regular expression repeatitively. At least the regular expressions should be reused.
image

@MartyIX
Copy link
Contributor

MartyIX commented Apr 7, 2023

How do you actually measure this please? I would love to measure impact of an analyzer of mine but I'm not sure how to do it.

@ninedan
Copy link
Contributor Author

ninedan commented Apr 7, 2023

Building a large .cs project, capturing a trace using PerfView. This stack is bad enough that any trace invoking it will show.

@bjornhellander
Copy link
Contributor

bjornhellander commented Apr 15, 2023

My understanding was that Regex.IsMatch caches the instance, but maybe the cache isn't big enough for everything needed while compiling a large solution.

I am having problems actually measuring this, but changing to having a static field with the Regex instead of calling Regex.IsMatch seems trivial. Do you see any downsides to that, @sharwell?

Or maybe rewrite to not use a Regex at all, since the pattern is so simple?

bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Apr 15, 2023
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Apr 15, 2023
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Apr 25, 2023
@sharwell sharwell added this to the 1.2-beta.next milestone Apr 25, 2023
@sharwell sharwell added the fixed label Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants