You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Format node fields directly when comment handling is unnecessary - #29853
When source maps are disabled and the Bloom filter rules out comments on a node, the formatter can call fmt_fields directly. This skips cloning the comment handle and writing empty leading and trailing comments. Nodes with possible comments or source maps still take the existing path.
Compared with #29852, the fast path used 4.44% fewer instructions across Ruffβs five formatter benchmarks and 2.79% fewer across ten Python standard-library modules. Synthetic assignments with leading and trailing comments used 0.13% more. These are medians from 21 paired arm64 trials that include trivia construction and printing.
Test Plan
The formatter tests passed, and the parent and this change produced identical formatted text and source-map markers across the comparison corpora.
β οΈ5 benchmarks with a significant change ran on different hardware
Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.
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
formatterRelated to the Ruff formatterperformancePotential performance improvement
2 participants
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 source maps are disabled and the Bloom filter rules out comments on a node, the formatter can call
fmt_fieldsdirectly. This skips cloning the comment handle and writing empty leading and trailing comments. Nodes with possible comments or source maps still take the existing path.Compared with #29852, the fast path used 4.44% fewer instructions across Ruffβs five formatter benchmarks and 2.79% fewer across ten Python standard-library modules. Synthetic assignments with leading and trailing comments used 0.13% more. These are medians from 21 paired arm64 trials that include trivia construction and printing.
Test Plan
The formatter tests passed, and the parent and this change produced identical formatted text and source-map markers across the comparison corpora.