Repository navigation
Conversation
When the rule of 3 keeps an ambiguous closer from pairing with the top of its delimiter stack, the stack is walked down for an opener of the same run length that the rule allows. Unclosed openers that can never pair stay on the stack, so each closer for which that search fails walks all of them again, and `*a **b` repeated n times takes O(n^2) time. Stack entries are only ever appended as new tuples or popped, so if the entry at the depth a failed search reached is still in place, nothing below it has changed. The processor records that depth and entry per token and run length, and a later search for the same length stops there.
Collaborator
|
It doesn't seem that this introduces any new cases of dropped text or notable slowdowns in other areas, and it does seem to improve speed in the targeted case. I would say this change looks good to me. |
facelessuser
approved these changes
Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When the rule of 3 (#1691) keeps an ambiguous closer from pairing with the top of its delimiter stack,
DelimiterProcessor._handle_matchwalks the stack down for an opener of the same run length that the rule allows. In the input above each**opener never closes and stays on the stack, so every*closer for which that search fails walks all of them again, which is O(n^2).Stack entries are only appended as new tuples or popped, so while the entry at the depth a failed search reached is still in place, nothing below it has changed and the next search for that token and length can stop there. Output is identical to master on 300,760 renders (all strings up to length 8 over
*,_,aand space, plus 63,000 random and repeated-pattern documents, with no extensions and withextra,smartyandlegacy_em). The skip is taken 3,011 times in that set, and a planted off-by-one in it changes the output. The added test takes 4.2 s on master and 0.6 s with the change.AI Assistance Disclosure
No AI tools were used in preparing this PR.
AI tools were used and I have disclosed which ones, and have fully reviewed and verified their output.
AI tools were use to assist with the following:
Checklist