Add fast-path for comment detection#9808
Merged
charliermarsh merged 1 commit intomainfrom Feb 5, 2024
Merged
Conversation
905202d to
dd1fe54
Compare
CodSpeed Performance ReportMerging #9808 will improve performances by 4.84%Comparing Summary
Benchmarks breakdown
|
MichaReiser
reviewed
Feb 4, 2024
| "with" => SimpleTokenKind::With, | ||
| "yield" => SimpleTokenKind::Yield, | ||
| _ => SimpleTokenKind::Other, // Potentially an identifier, but only if it isn't a string prefix. We can ignore this for now https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals | ||
| _ => SimpleTokenKind::Name, // Potentially an identifier, but only if it isn't a string prefix. We can ignore this for now https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals |
Member
There was a problem hiding this comment.
How can we avoid returning a Name for a string prefix?
03a1844 to
a78aec3
Compare
Contributor
|
MichaReiser
requested changes
Feb 5, 2024
MichaReiser
approved these changes
Feb 5, 2024
a78aec3 to
03dcbf5
Compare
03dcbf5 to
c63bc5e
Compare
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.
Summary
When we fall through to parsing, the comment-detection rule is a significant portion of lint time. This PR adds an additional fast heuristic whereby we abort if a comment contains two consecutive name tokens (via the zero-allocation lexer). For the
ctypeslib.py, which has a few cases that are now caught by this, it's a 2.5x speedup for the rule (and a 20% speedup for token-based rules).