-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Intrinsicify SpanHelpers.IndexOfAny(char,char) #40589
Intrinsicify SpanHelpers.IndexOfAny(char,char) #40589
Conversation
{ | ||
Debug.Assert(length >= 0); | ||
// If vectors are supported, we first align to Vector. | ||
// If the searchSpan has not been fixed or pinned the GC can relocate it during the | ||
// execution of this method, so the alignment only acts as best endeavour. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 thanks for the comment (cf. #11703).
Regex uses IndexOfAny(char, char) and IndexOfAny(char, char, char) so would presumably benefit from this. |
Same request for perf numbers please - thanks! |
Ideally we'd test this specifically with regex redux, which spends something like 30% of the time now inside of IndexOfAny(char, char). While it'd be great if it made it faster, I also want to confirm it doesn't make it slower. If memory serves, it was spending a lot of its time in the non-vectorized portion of the method. |
@stephentoub is that in the performance repo? |
fcb5c78
to
ff3f2cf
Compare
ff3f2cf
to
92a2679
Compare
Dealing with the alignment loses most of the benefit, so have updated it to match the approach I took for +10%
|
10% is significant on that one. This might be worth getting creative to try to get into this release. @benaadams was that with IndexOfAny(char, char, char) changes as well? I would expect that to be relevant also: https://github.com/dotnet/performance/blob/master/src/benchmarks/micro/runtime/BenchmarksGame/regex-redux-5.cs#L60-L68 |
Just noticed that's with deleting |
Let me put them all in one as they are basically identical methods |
All your IndexOf PR's into one? That sounds like a good idea, thanks. |
Your perf numbers above demonstrate that the interpreter doesn't use IndexOfAny at all. @stephentoub had this listed in #1349 and it's checked off so maybe he tried it and it didn't give a win somehow. |
I probably checked it off in error, or having employed IndexOf but not IndexOfAny. There's a TODO in the code for the IndexOfAny (and some other related optimizations): Lines 444 to 450 in 19a4297
I don't think I ever got around to evaluating the trade-off that would be required here, the overhead of extracting from the char class the 2 or 3 characters that could be used with IndexOfAny and then using IndexOfAny. |
OK, I un-checked it for some future day. Presumably the value could only be higher in the interpreter, since the runtime is larger. |
Not necessarily. With the compiler we get to compute the right thing to do once, and there's then no overhead at execution time, since the choice to use IndexOfAny and the arguments to it are all pre-computed. With the interpreter, we either need to redetermine that every time we invoke FindFirstChar, or we need to compute it once and store that data away somewhere, then check whether we have it and use it. It would certainly be beneficial when the things being searched for are few and far between, but if the IndexOfAny is used to search for something that frequently presents itself very quickly, it might be a net loss. Someone would need to do the work and then see whether it's fruitful on a variety of benchmarks. |
Superseded by #40729 |
Updated
Intrinsicify SpanHelpers.IndexOfAny(char,char)
dotnet/coreclr#22877Resolves: #12094