microsoft / microsoft/STL

`<regex>`: Avoid generating no-op NFA nodes

Open
#5,962 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

performance regex
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

The NFA nodes of type _N_nop, _N_group and _N_end_group do not result in any changes to the match state in the matcher. However, processing them still requires some time. Going by the benchmarks in #5939, it seems about 2.5 ns are spent on my machine whenever when such a node is encountered by the matcher; see, e.g., the 37 % (relative) / 470 ns (absolute) increase in running time when matching the pattern (?:a)* to 100 a's compared to a*.

Note that these NFA nodes do usually serve some purpose during regex parsing, so resolving this issue requires some careful changes to the parser logic.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the regex parser and matcher logic described in the issue, then review the benchmark referenced in #5939, especially the (?:a)* versus a* case. Trace how _N_nop, _N_group, and _N_end_group nodes are produced and processed. Done means preserving regex behavior while avoiding unnecessary nodes and demonstrating reduced matching overhead.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.