Repository navigation
Use a Bloom filter for formatter comment lookups - #29852
Merged
Merged
Conversation
MichaReiser
temporarily deployed
to
automations
October 30, 2026 19:23 — with
GitHub Actions
Inactive
Contributor
|
MichaReiser
had a problem deploying
to
automations
October 30, 2026 19:33 — with
GitHub Actions
Error
MichaReiser
temporarily deployed
to
automations
October 30, 2026 19:36 — with
GitHub Actions
Inactive
MichaReiser
marked this pull request as ready for review
October 30, 2026 20:01
charliermarsh
approved these changes
Oct 30, 2026
MichaReiser
added a commit
that referenced
this pull request
Oct 30, 2026
) ## Summary 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.
10 tasks
This branch was previously deployed
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
Most nodes have no attached comments. A 256-byte Bloom filter lets the formatter skip the comment map lookup when a node's address maps to a clear bit. On a hit, the formatter still checks the map.
Building and printing pre-parsed documents on arm64 took 4.82% fewer instructions across five Ruff benchmark fixtures and 3.40% fewer across ten Python standard-library modules, measured as the median of 21 paired runs against
main. A synthetic workload with leading and trailing comments on every assignment took 0.38% more instructions.Test Plan
The formatter tests passed, including a forced filter collision, and all benchmark inputs produced byte-for-byte identical output.