Change NoqaCode to a single string with an offset#18736
Closed
Conversation
NoqaCode to a single string with an offset
Contributor
|
Member
|
I wonder if this refactor is worth it, considering that it's a slow down. Should we wait until we add |
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
This PR explores two potential and closely related
NoqaCoderefactors. The first, in the first two commits, replaces the currentNoqaCode(&'static str, &'static str)withNoqaCode(&'static str, usize), where theusizeis the index where the prefix and suffix separate. As detailed in this comment, it's not really possible to get a nice, single&'static str, but we can hack around it with aLazyLockto callformat!in astatic:ruff/crates/ruff_macros/src/map_codes.rs
Lines 293 to 295 in 7ff37f4
In the third commit, I just tried
NoqaCode(String, usize), which meansNoqaCodecan no longer beCopy, but is otherwise a bit more natural.Test Plan
Codspeed benchmarks on this PR. The
&'static strversion didn't show any difference, but theStringversion shows up to a 3% regression. Still, either of these representations should be a bit better if we end up needing to callRule::from_codesince they will avoid having to allocate a new string just to pass it there. A single string should be easier to store onruff_db::Diagnostictoo.ruff/crates/ruff_linter/src/registry.rs
Lines 19 to 21 in 9cb0243