Skip to content

<regex>: Avoid generating _N_nop nodes when parsing assertions - #6199

Merged
Stephan T. Lavavej (StephanTLavavej) merged 1 commit into
microsoft:mainfrom
muellerj2:regex-remove-nop-node-at-assertion-start
Apr 17, 2026
Merged

<regex>: Avoid generating _N_nop nodes when parsing assertions#6199
Stephan T. Lavavej (StephanTLavavej) merged 1 commit into
microsoft:mainfrom
muellerj2:regex-remove-nop-node-at-assertion-start

Conversation

@muellerj2

Copy link
Copy Markdown

Towards #5962.

This removes the generation of _N_nop nodes when parsing assertions. Such a node was generated so that the NFA branch for the body of the assertion could be attached to it. But we can just as well initially generate the branch for the assertion body as the successor of the _N_assert node, as though the body wouldn't be part of the assertion but follow it, and then relink the branch into the correct position as the child of the _N_assert node.

This appears to have been the last (and maybe always the only) case where the parser generated _N_nop nodes. But we must keep around the code in the matcher that handles this node type until vNext.

Benchmark

Small but consistent improvement for assertions:

benchmark before [ns] after [ns] speedup
bm_lorem_search/"^bibe"/2 54.6875 50.2232 1.09
bm_lorem_search/"^bibe"/3 54.6875 51.6183 1.06
bm_lorem_search/"^bibe"/4 53.0134 53.0134 1.00
bm_lorem_search/"bibe"/2 2999.44 2849.48 1.05
bm_lorem_search/"bibe"/3 5580.36 5580.36 1.00
bm_lorem_search/"bibe"/4 11962.9 11474.6 1.04
bm_lorem_search/"bibe".collate/2 2982.01 2982.01 1.00
bm_lorem_search/"bibe".collate/3 5580.36 5719.87 0.98
bm_lorem_search/"bibe".collate/4 11474.6 11439.7 1.00
bm_lorem_search/"(bibe)"/2 3766.73 3599.32 1.05
bm_lorem_search/"(bibe)"/3 7114.96 6975.45 1.02
bm_lorem_search/"(bibe)"/4 14508.9 14439.1 1.00
bm_lorem_search/"(bibe)+"/2 4882.81 4813.07 1.01
bm_lorem_search/"(bibe)+"/3 9416.81 8998.29 1.05
bm_lorem_search/"(bibe)+"/4 18415.3 17578.3 1.05
bm_lorem_search/"(?:bibe)+"/2 3989.95 4143.41 0.96
bm_lorem_search/"(?:bibe)+"/3 8021.76 7812.5 1.03
bm_lorem_search/"(?:bibe)+"/4 15694.8 15346 1.02
bm_lorem_search/R"(\bbibe)"/2 66266.7 66964.3 0.99
bm_lorem_search/R"(\bbibe)"/3 131830 125558 1.05
bm_lorem_search/R"(\bbibe)"/4 254981 254981 1.00
bm_lorem_search/R"(\Bibe)"/2 142997 141246 1.01
bm_lorem_search/R"(\Bibe)"/3 295048 278308 1.06
bm_lorem_search/R"(\Bibe)"/4 599888 585938 1.02
bm_lorem_search/R"((?=....)bibe)"/2 5000 4349.18 1.15
bm_lorem_search/R"((?=....)bibe)"/3 9416.81 8579.76 1.10
bm_lorem_search/R"((?=....)bibe)"/4 19252.4 17648 1.09
bm_lorem_search/R"((?=bibe)....)"/2 4080.63 3850.44 1.06
bm_lorem_search/R"((?=bibe)....)"/3 8021.76 7812.5 1.03
bm_lorem_search/R"((?=bibe)....)"/4 16392.3 15380.8 1.07
bm_lorem_search/R"((?!lorem)bibe)"/2 3609.79 3369.15 1.07
bm_lorem_search/R"((?!lorem)bibe)"/3 6696.43 6277.9 1.07
bm_lorem_search/R"((?!lorem)bibe)"/4 13497.4 13113.8 1.03
bm_lorem_search/"(bibe|soda)"/2 8998.29 8998.29 1.00
bm_lorem_search/"(bibe|soda)"/3 18136.2 17648 1.03
bm_lorem_search/"(bibe|soda)"/4 36062.4 34527.8 1.04
bm_lorem_search/"(id )?bibe"/2 8370.54 8370.54 1.00
bm_lorem_search/"(id )?bibe"/3 16043.5 16392.3 0.98
bm_lorem_search/"(id )?bibe"/4 33691.9 32784.6 1.03
bm_lorem_search/".bibe"/2 3138.95 3048.28 1.03
bm_lorem_search/".bibe"/3 5937.5 5719.87 1.04
bm_lorem_search/".bibe"/4 11160.7 11718.8 0.95
@muellerj2
Julian Müller (muellerj2) requested a review from a team as a code owner April 3, 2026 19:33
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Apr 3, 2026
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added performance Must go faster regex meow is a substring of homeowner labels Apr 3, 2026
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Initial Review to Ready To Merge in STL Code Reviews Apr 4, 2026
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Ready To Merge to Merging in STL Code Reviews Apr 15, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo. Please notify me if any further changes are pushed, otherwise no action is required.

@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit e60708d into microsoft:main Apr 17, 2026
49 checks passed
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Apr 17, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

🐈 🐈‍⬛ 😻

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

3 participants