Skip to content

Conversation

@muellerj2
Copy link
Contributor

Towards #5957. This implements recognition of branchless but non-simple (=reentrant) loops and expands the stack growth optimization in the matcher to such loops. The main change is to recognize such loops in the parser and make it set a new flag on such loops; the changes to the matcher are minimal, just requiring two line changes: One to teach it about the flag and the other one to teach the code in the _N_end_rep handler for simple/branchless loops about a different opcode used in the _N_rep handler for reentrant greedy loops.

This PR does not implement the corresponding change for non-reentrant loops. It would be easy to do so, since the updated _Compute_loop_simplicity() already recognizes such loops. But I'm skeptical that the optimization for non-reentrant loops is actually worth it: It avoids a few assignments in exchange for a branch and more code. For this reason, I would like to do some benchmarking first before I allocate a flag bit to non-reentrancy.

Benchmark:

benchmark before [ns] after [ns] speedup
bm_match_sequence_of_9a1b/"(?:a*b)*"/100 24553.6 15346 1.60
bm_match_sequence_of_9a1b/"(?:a*b)*"/200 73242.2 32470.6 2.26
bm_match_sequence_of_9a1b/"(?:a*b)*"/400 111607 73242.2 1.52

@muellerj2 muellerj2 requested a review from a team as a code owner January 17, 2026 20:42
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Jan 17, 2026
@StephanTLavavej StephanTLavavej added performance Must go faster regex meow is a substring of homeowner labels Jan 17, 2026
@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in STL Code Reviews Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Must go faster regex meow is a substring of homeowner

Projects

Status: Ready To Merge

Development

Successfully merging this pull request may close these issues.

2 participants