Skip to content

Optimize symbolic regex Antimirov mode to avoid so much allocation #60918

Closed

Description

@stephentoub

When in Antimirov mode, we logically maintain a list of states we're currently in and, for each step, generate a new list of states based on looking at each current state and determining all the states it could lead us to. However, rather than something like:

HashSet<Node> nextStates = _nextStates;
HashSet<Node> currentStates = _currentStates;
foreach (Node current in currentStates)
{
    foreach (Node next in Transition(current))
    {
        nextStates.Add(next);
    }
}
currentStates.Clear();
_nextStates = currentStates;
_currentStates = nextStates;

it's implemented using an immutable SymbolicRegexNode, where every additional state found involves unioning in the new state into the next states node, which means generating one or more new nodes for each additional state we union in.

Activity

  1. ghost added
    untriaged
    on Oct 27, 2021
  2. added this to the 7.0.0 milestone on Oct 27, 2021
  3. added
    tenet-performance
    and removed
    untriaged
    on Oct 27, 2021
  4. stephentoub commented on Dec 10, 2021

    @stephentoub
    MemberAuthor

    @veanes, I believe you're working on this or a very related optimization, right?

  5. veanes commented on Dec 10, 2021

    @veanes
    Contributor

    Yes, started but got sidetracked a bit, will try to get this done soon (within a few days), essentially improving the overhead in the Antimirov mode, regarding state-set representation (using a more lightweight def, initially just HashSet<int>, Olli has then in mind a specialized very efficient "small integer set" data structure (similar to what is in use for NFA simulation ie Antimirov-like mode, in other tools like re2) to optimize further and can swap that out then.)

  6. veanes commented on Feb 21, 2022

    @veanes
    Contributor

    The PR #65637 should fix this issue, once this has been validated.

  7. ghost added
    in-pr
    on Feb 25, 2022
  8. ghost removed
    in-pr
    on Feb 26, 2022
  9. ghost locked as resolved and limited conversation to collaborators on Mar 28, 2022
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