Skip to content

Improve SpanHelpers.IndexOfAny throughput / vectorization #25023

Description

@stephentoub

Our regex engine can now spend a decent amount of time inside of span helpers like:

public static unsafe int IndexOfAny(ref char searchSpace, char value0, char value1, int length)

and in particular, we seem to hit this path:
if (pCh[0] == value0 || pCh[0] == value1)
goto Found;
if (pCh[1] == value0 || pCh[1] == value1)
goto Found1;
if (pCh[2] == value0 || pCh[2] == value1)
goto Found2;
if (pCh[3] == value0 || pCh[3] == value1)
goto Found3;

fairly frequently. It'd be great to investigate whether we can do anything to improve the performance of these IndexOfAny helpers, whether it's by improving how we do the vectorization, or utilizing intrinsics directly if that would help, etc. I believe @tannergooding had some ideas.

For example, we spend ~30% of the time in the regex redux benchmark in this helper:
image

cc: @danmosemsft

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions