perf: Hoist resize within puts - #440
Merged
Merged
Conversation
epage
added a commit
to astral-sh/ruff
that referenced
this pull request
Jul 28, 2026
## Summary This is a first step towards #20411. After this, we would work to either upstream changes or adjust things within Ruff. Performance improvements have already been upstreamed (rust-lang/annotate-snippets-rs#437, rust-lang/annotate-snippets-rs#440) Re-implemented the following from the fork: - Hidden snippets (rust-lang/annotate-snippets-rs#448) - Renderer-level disabling of hyperlinks - Jupyter cell indices (rust-lang/annotate-snippets-rs#449) - Fixable mark (rust-lang/annotate-snippets-rs#450) - `lineno_offset` (maybe not needed if #20648 is taken care of) - anonymized lines affects origin (rust-lang/annotate-snippets-rs#451) - cut indicator (maybe not needed if we can switch to unicode renderer) Additional hacks to minimize behavior change include - Adjust upstream's hidden severity behavior to match Ruff's (rust-lang/annotate-snippets-rs#452) - How newlines are annotated (rust-lang/annotate-snippets-rs#454) - To not indent for line numbers when none will be present (rust-lang/annotate-snippets-rs#453) - Enabling `simd` by default All of the above represents work that needs to be resolved to address #20411. `lib.name` hack is used to simplify maintenance with the assumption that we'll continue working towards #20411. Behavior changes that were included - Tweak when implicit padding lines are present - Fix Origin's line/column is now derived from the primary annotation - Make consistent the rendering of primary/context annotations - Fix snippets to show up for empty source (but may degrade #24528) - Fix handling of term width - Fix rendering of annotations between newline and first character (granted, maybe the caller is wrong) - Tweak multiline annotation markers New or upcoming features annotate-snippets features that we will be able to leverage by moving this forward - `AnnotationKind::Visible` to improve the quality of built-in code-folding if Ruff were to switch to it - `DecorStyle::Unicode` - *(upcoming)* No-graphiscs mode for screen readers (may also be useful for AIs) Deferred: - Moving related `Group`s into the same `Report` - Using `secondary_title` for any `Group` after the first in a `Report` - Using a `Snippet`, instead of titles, for "virtual code" like #27033 (comment) - Switching hidden snippets to `Origin` ## Test Plan Within cpython, I ran ```console $ hyperfine -i "../../ruff/target-baseline/release/ruff check" "../../ruff/target-update/release/ruff check" -N -m20 --output=null Benchmark 1: ../../ruff/target-baseline/release/ruff check Time (mean ± σ): 27.5 ms ± 1.1 ms [User: 33.0 ms, System: 108.4 ms] Range (min … max): 25.0 ms … 31.7 ms 94 runs Warning: Ignoring non-zero exit code. Benchmark 2: ../../ruff/target-update/release/ruff check Time (mean ± σ): 28.1 ms ± 2.0 ms [User: 33.4 ms, System: 105.7 ms] Range (min … max): 24.8 ms … 38.9 ms 102 runs Warning: Ignoring non-zero exit code. Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use t he '--warmup' or '--prepare' options. Summary ../../ruff/target-baseline/release/ruff check ran 1.03 ± 0.08 times faster than ../../ruff/target-update/release/ruff check ``` Before: <img width="486" height="583" alt="image" src="https://github.com/user-attachments/assets/2d94dabf-b28d-48c1-b17c-52aac59fd57e" /> After: <img width="486" height="583" alt="image" src="https://github.com/user-attachments/assets/b388ada3-e3d7-4ba0-b90b-1330eb81f4be" />
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.
This causes the
simplebenchmark to take about 8% less time.This was the change deferred out of #437. I hadn't noticed that ruff's empty string check was load bearing.