Skip to content

Extend Regex 32-bit/64-bit read optimization to IgnoreCase as well #62459

Closed

Description

@stephentoub

When comparing a string in a regex (RegexNode.Multi), we unroll the matching for smaller strings. But rather than reading and comparing a single character at a time, we try to read/compare two or four characters at a time by reading the data as a UInt32 or UInt64. We were never able to do this with RegexOptions.IgnoreCase, however, because the design demanded that we char.ToLower each individual character read from the input. But, we're now switching to a design where casing is almost entirely handled at parse time (#61048), where most letters are then parsed into a set, e.g. 'a' becomes '[Aa]'. For most of ASCII, then, we can actually apply this optimization, e.g. the string "abcd" becomes "[Aa][Bb][Cc][Dd]", and we can read a UInt64 input OR'd with 0x20202020, and then compare it against the precomputed UInt64 value similarly OR'd with 0x20202020. This will give us most of the vectorization gains we see for case-sensitive for case-insensitive as well.

Activity

  1. added
    tenet-performance
    on Dec 6, 2021
  2. ghost added
    untriaged
    on Dec 6, 2021
  3. removed
    untriaged
    on Dec 6, 2021
  4. added this to the 7.0.0 milestone on Dec 6, 2021
  5. stephentoub commented on Mar 11, 2022

    @stephentoub
    MemberAuthor

    Fixed by #66339

  6. ghost locked as resolved and limited conversation to collaborators on Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions