Skip to content

Compile RegEx to improve performance #2451

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

Merged
merged 1 commit into from
Sep 21, 2017
Merged

Compile RegEx to improve performance #2451

merged 1 commit into from
Sep 21, 2017

Conversation

rprouse
Copy link
Member

@rprouse rprouse commented Sep 21, 2017

@OsirisTerje and I have been working with the Visual Studio test team looking at performance. Our XML serialization in TNode shows up as a bottleneck for performance which isn't really a surprise. One area in there that showed up fairly high was our use of RegEx to escape invalid XML characters. We create this RegEx as a static and use it many times. Adding the compiled option to the RegEx produced a small performance gain, so I did the same for our two other long lasting RegEx's.

This was tested using a test project from the VSTest team with 10,000 empty test methods. Running those tests using the console, in-process, compiled release, took an average of 10.65 sec over 4 runs. With this fix, the average for 4 runs drops to 9.65 sec.

Even though this is nearly a 10% performance gain, it is only for trivial tests and the gain would be smaller if the tests were more complex. It is a minor fix though, so probably worth it.

@rprouse rprouse added this to the 3.9 milestone Sep 21, 2017
@rprouse rprouse requested a review from OsirisTerje September 21, 2017 18:25
Copy link
Member

@mikkelbu mikkelbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rprouse rprouse merged commit 50272ea into master Sep 21, 2017
@rprouse rprouse deleted the regex_performance branch September 21, 2017 20:59
@ChrisMaddock
Copy link
Member

Looks good!

Out of interest, did you compare this to using something like XmlConvert.IsXmlChar() over our own regex? It's only post-.NET-4.0, but could be worth using on the platforms where it's available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants