Repository navigation
🐛 fix(xpath): charge regex group resets to budget - #2131
Conversation
A back-reference pattern cleared every capture slot again at each start position, and that work was not counted against the regex step budget. A pattern with many groups therefore cost the slot count times the number of positions outside the limit. Clear the slots once per search instead. A failed attempt unwinds its trail and restores every slot it wrote, so the next position starts from the same state. The slot count is charged to the budget before the search begins. Fixes tox-dev#1746
Merging this PR will regress 1 benchmark2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
A back-reference pattern could run past its step budget in
matches,replace,re:testandre:replace. Clearing the capture slots before each start position was work the budget did not count, so a pattern with many capture groups did more work than its limit allowed. 🛡️ After this change the clearing happens once per search and is charged to the budget before matching starts.Architecture
The search clears the capture slots once, before the first start position. A failed attempt restores every slot it wrote, so each start position still begins from the state it would have had before. The clearing is charged to the same budget as matching, and a search that spends its budget raises the existing
ValueError.Behavior changes
ValueErrorwhere it returned a result before.Fixes #1746.