`<regex>`: Extend some optimizations for simple loops to branchless but reentrant and branching but non-reentrant loops
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
A simple loop is non-reentrant and branchless, but each implemented optimization for simple loops only depends on one of these properties. We should therefore extend these optimizations to such loops that satisfy one property but not the other.
This means that the parser has to detect non-reentrancy and branchlessness independently from each other and set appropriate flags on the loop nodes. Afterwards, the matcher has to be changed to apply an optimization not just to simple loops but also when the flag for the required property is set.
It should certainly be worth it to implement this for branchless-but-reentrant loops, as this extends #5939's stack growth optimization to many more loops such as [^a]+ in the regex (a[^a]+)+. This might greatly reduce stack usage and thus time spent on reallocating the stack frame buffer, but also makes it less likely that regex matching hits the stack limit.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the regex parser's loop-node handling and the matcher paths that currently recognize simple loops; inspect issue #5939 for the related stack-growth optimization. Done means non-reentrancy and branchlessness are tracked independently and the relevant optimizations apply when their required property is present, including the described nested-loop case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100