Skip to content

Format node fields directly when comment handling is unnecessary - #29853

Merged
MichaReiser merged 1 commit into
micha/formatter-comment-bloom-filterfrom
micha/formatter-fast-fmt-fields
Oct 30, 2026
Merged

MichaReiser merged 1 commit into
micha/formatter-comment-bloom-filterfrom
micha/formatter-fast-fmt-fields

Conversation

@MichaReiser

@MichaReiser MichaReiser commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

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.

@MichaReiser MichaReiser added performance Potential performance improvement formatter Related to the Ruff formatter labels Oct 30, 2026
@astral-automations-bot

Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Formatter (stable)

βœ… ecosystem check detected no format changes.

Formatter (preview)

βœ… ecosystem check detected no format changes.

Formatter (stable) Β· Formatter (preview)


Results for 7d4a67d Β· Workflow run

@codspeed

codspeed Bot commented Oct 30, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 5.16%

1 warning

⚠️ 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.

Learn more about Macro Runners

See affected benchmarks

⚑ 5 improved benchmarks
βœ… 55 untouched benchmarks
⏩ 238 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚑ CPU Simulation formatter[large/dataset.py] 15.7 ms 14.8 ms +6.01%
⚑ CPU Simulation formatter[pydantic/types.py] 6.3 ms 6 ms +5.54%
⚑ CPU Simulation formatter[unicode/pypinyin.py] 1.2 ms 1.1 ms +4.96%
⚑ CPU Simulation formatter[numpy/ctypeslib.py] 3.3 ms 3.1 ms +4.71%
⚑ CPU Simulation formatter[numpy/globals.py] 433.9 ¡s 414.9 ¡s +4.59%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing micha/formatter-fast-fmt-fields (7d4a67d) with micha/formatter-comment-bloom-filter (5140094)

Open in CodSpeed

Footnotes

  1. 238 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@MichaReiser
MichaReiser marked this pull request as ready for review October 30, 2026 20:00
@MichaReiser
MichaReiser added this pull request to stack #29854 October 30, 2026 20:01
@MichaReiser
MichaReiser merged commit f93c0b1 into main Oct 30, 2026
56 checks passed
@MichaReiser
MichaReiser deleted the micha/formatter-fast-fmt-fields branch October 30, 2026 21:10

This branch was previously deployed

1 inactive deployment
automations β€” 7d4a67d6 Deployed Oct 30, 2026 by MichaReiser via security-review / security review #96357
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

formatter Related to the Ruff formatter performance Potential performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants