Repository navigation
gh-160556: Fix quadratic time in csv.Sniffer with long runs of spaces - #160557
Open
devdavidejesus wants to merge 1 commit into
Open
devdavidejesus wants to merge 1 commit into
devdavidejesus wants to merge 1 commit into
Conversation
…spaces Sniffer._split_dormant() tried a match at every space of a run of spaces when the space was a candidate delimiter, and rescanned the rest of the run each time. A match starting at a space preceded by a space is never the leftmost one, so skip those positions with a lookbehind. The results do not change. The regression was introduced in pythongh-83273 (25fea6d).
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.
Sniffer._split_dormant()searched for(?:^|([\r\n{cls}])) *{quotechar}. When the space is a candidate delimiter, the search tried a match at every space of a run and rescanned the rest of the run each time, so a long run of spaces not followed by a quote character took quadratic time.A match starting at a space preceded by a space is never the leftmost one, because a match with the same group and end starts at the beginning of the run. The lookbehind
(?<! )skips those positions, so the results do not change.Tested on macOS with a debug build of main:
('a,b' + ' ' * 100_000 + 'c"\n') * 4(the new test's sample) now takes 0.06 s instead of 23.2 s;test_csvpasses, also with-R 3:3.The regression was introduced in gh-83273 and is in 3.16.0a1.
See #160556.