Skip to content

Reduce formatter source-slice overhead - #29855

Merged
MichaReiser merged 4 commits into
mainfrom
micha/formatter-reuse-source-slice
Oct 30, 2026
Merged

MichaReiser merged 4 commits into
mainfrom
micha/formatter-reuse-source-slice

Conversation

@MichaReiser

@MichaReiser MichaReiser commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Compile the formatter's newline-check helper and its calls only when debug assertions are enabled, eliminating an unnecessary source-slice read in release builds. Inline source-slice access so callers can optimize the remaining reads, and use track_caller to report the failing debug check's call site.

Local Apple silicon measurements of formatting and printing pre-parsed files used 1.61% fewer retired instructions across the five Ruff formatter benchmark inputs and 1.18% fewer across ten Python standard-library files, compared with 08aac42edb. Elapsed-time differences were within measurement noise.

Test Plan

The formatter tests and Clippy pass, and formatted text and source maps match the base revision.

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

astral-automations-bot Bot commented Oct 30, 2026 •

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 61dd4a4 Β· Workflow run

@MichaReiser MichaReiser changed the title Reuse source text when formatting a source slice Compile out formatter newline checks and their arguments Oct 30, 2026
@MichaReiser MichaReiser changed the title Compile out formatter newline checks and their arguments Reduce formatter source-slice overhead Oct 30, 2026
@MichaReiser
MichaReiser marked this pull request as ready for review October 30, 2026 22:03
@MichaReiser
MichaReiser merged commit 3b5d4a6 into main Oct 30, 2026
55 checks passed
@MichaReiser
MichaReiser deleted the micha/formatter-reuse-source-slice branch October 30, 2026 22:03

This branch was previously deployed

1 inactive deployment
automations β€” 61dd4a4e Deployed Oct 30, 2026 by MichaReiser via security-review / security review #96382
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.

1 participant