Speed up line-numbered syntax word wrap#4178
Open
KRRT7 wants to merge 3 commits into
Open
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4178 +/- ##
=======================================
Coverage ? 97.81%
=======================================
Files ? 96
Lines ? 8390
Branches ? 0
=======================================
Hits ? 8207
Misses ? 183
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Jun 29, 2026
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
Optimizes
Syntax(word_wrap=True, line_numbers=True)by wrapping each highlightedTextsource line directly instead of routing every source line throughConsole.render_lines(...).This stacks on #4177 and targets the remaining line-numbered wrapping path.
Chiasmus framing
Observed:
Syntax(word_wrap=True, line_numbers=True)renders each source line separately throughConsole.render_lines(...)so it can prefix only the first visual row with a line number.Mirrored target:
Keep per-source-line numbering, but avoid the heavier
Console.render_lines(...)pipeline by usingText.wrap(...)and rendering the wrapped rows directly.Hypothesis:
Per-source-line
render_linescalls are a meaningful share of runtime for syntax output with many line-numbered lines.Target workload
User-visible operation:
Console.print(Syntax(...))for line-numbered, word-wrapped Python syntax output.Workload:
Environment:
Darwin Kernel Version 25.5.0Performance
Before, on #4177 tip before this change:
After:
This is about an 11.5% speedup for the target workload.
Correctness
I also smoke-tested the new ASV benchmark method:
Tradeoffs
No new cache or retained state. The implementation duplicates the small part of
Console.render_lines(...)needed for this hot path: style application and fixed-width line adjustment afterText.wrap(...).Stack
optimize-syntax-word-wrapmainperf/syntax-line-numbers-word-wrap