Repository navigation
perf: share parsed regexes between expectations - #1788
Merged
Merged
Conversation
Every expectation has string options of its own, so a regex pattern was parsed again for every evaluation, and `AsRegex(RegexOptions)` parsed an empty pattern just to validate the options. With `RegexOptions.Compiled` this emitted IL twice per assertion. The parsed regexes are now kept in a bounded cache keyed by pattern, options and culture.
| Benchmark | Before | After |
|---|---:|---:|
| `IsEqualTo("order-[0-9]+").AsRegex()` | 1.285 µs / 3 KB | 310.5 ns / 656 B |
| `IsEqualTo("order-[0-9]+").AsRegex(RegexOptions.Compiled)` | 1039.4 µs / 16.96 KB | 265.1 ns / 680 B |
| `IsEqualTo("ORDER-[0-9]+").AsRegex().IgnoringCase()` | 2.152 µs / 3.87 KB | 373.9 ns / 656 B |
vbreuss
enabled auto-merge (squash)
October 11, 2026 08:43
|
Contributor
Test Results 91 files ± 0 91 suites ±0 1h 47m 18s ⏱️ - 2m 15s Results for commit d15bf64. ± Comparison against base commit 7790486. This pull request removes 4958 and adds 4869 tests. Note that renamed tests count towards both. |
Contributor
🚀 Benchmark ResultsDetails
|
github-actions Bot
added a commit
that referenced
this pull request
Oct 11, 2026
…ctations (#1788) by Valentin Breuß
github-actions Bot
added a commit
that referenced
this pull request
Oct 11, 2026
…ctations (#1788) by Valentin Breuß
Contributor
|
This is addressed in release v3.1.0. |
This was referenced Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Every expectation has string options of its own, so a regex pattern was parsed again for every evaluation, and
AsRegex(RegexOptions)parsed an empty pattern just to validate the options. WithRegexOptions.Compiledthis emitted IL twice per assertion. The parsed regexes are now kept in a bounded cache keyed by pattern, options and culture.IsEqualTo("order-[0-9]+").AsRegex()