Compile RegEx to improve performance #2451
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@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 thisRegEx
as a static and use it many times. Adding the compiled option to theRegEx
produced a small performance gain, so I did the same for our two other long lastingRegEx
'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.