Skip to content

Enable Regex to use SearchValues<string> in compiled / source generator for IgnoreCase multi-strings - #98791

Merged
stephentoub merged 5 commits into
dotnet:mainfrom
stephentoub:usesearchvaluesstringinregex
Feb 23, 2024
Merged

Enable Regex to use SearchValues<string> in compiled / source generator for IgnoreCase multi-strings#98791
stephentoub merged 5 commits into
dotnet:mainfrom
stephentoub:usesearchvaluesstringinregex

Conversation

@stephentoub

@stephentoubstephentoub commented Feb 22, 2024

Copy link
Copy Markdown
Member

The analyzer determines a set of prefixes that can start any match, and then uses SearchValues<string> with IndexOfAny to find the next one from that set. It's currently only enabled for case-insensitive; we need to do some more perf validation before enabling for case-sensitive.

MethodToolchainPatternOptionsMeanRatio
Count\main\corerun.exe(?i)Sher[a-z]+|Hol[a-z]+Compiled691.66 us1.00
Count\pr\corerun.exe(?i)Sher[a-z]+|Hol[a-z]+Compiled130.90 us0.19
Count\main\corerun.exe(?i)Sherlock|Holmes|WatsonCompiled873.37 us1.00
Count\pr\corerun.exe(?i)Sherlock|Holmes|WatsonCompiled132.12 us0.15

Contributes to #85693

…or TryFindNextStartingPosition
The analyzer determines a set of prefixes that can start any match, and then uses SearchValues with IndexOfAny to find the next one from that set. It's currently only enabled for case-insensitive; we need to do some more perf validation before enabling for case-sensitive.

@MihaZupanMihaZupan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🎉

Comment threadsrc/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs Outdated
Comment on lines +51 to +52
// Arbitrary string length limit (with some wiggle room) to avoid creating strings that are longer than is useful and consuming too much memory.
const int MaxPrefixLength = 8;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

longer than is useful and consuming too much memory

This is mainly about not spending too many resources on the analysis part, not about the cost of the potential SearchValues itself, right?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Correct

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Well, "the longer than is useful" part was about SearchValues itself. Is that not the case?

@danmoseley

Copy link
Copy Markdown
Contributor

A lot of work to get to this point! I guess I should remeasure the rust benchmarks with all the alternations.

@ghost

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

Issue Details

The analyzer determines a set of prefixes that can start any match, and then uses SearchValues<string> with IndexOfAny to find the next one from that set. It's currently only enabled for case-insensitive; we need to do some more perf validation before enabling for case-sensitive.

MethodToolchainPatternOptionsMeanRatio
Count\main\corerun.exe(?i)Sher[a-z]+|Hol[a-z]+Compiled691.66 us1.00
Count\pr\corerun.exe(?i)Sher[a-z]+|Hol[a-z]+Compiled130.90 us0.19
Count\main\corerun.exe(?i)Sherlock|Holmes|WatsonCompiled873.37 us1.00
Count\pr\corerun.exe(?i)Sherlock|Holmes|WatsonCompiled132.12 us0.15

Contributes to #85693

Author:stephentoub
Assignees:stephentoub
Labels:

area-System.Text.RegularExpressions

Milestone:-

@DrewScoggins

DrewScoggins commented Feb 27, 2024

Copy link
Copy Markdown
Member

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@stephentoub@danmoseley@DrewScoggins@MihaZupan