Wrap syntax text directly#4179
Open
KRRT7 wants to merge 4 commits into
Open
Conversation
2bca925 to
6853707
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4179 +/- ##
=======================================
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=False)by wrapping the highlightedTextdirectly and yielding adjusted segments, instead of sending the whole renderable throughConsole.render_lines(...).This stacks on #4178 and continues the syntax word-wrap performance work.
Performance framing
Observed:
The no-line-number word-wrap path still routes large syntax output through
Console.render_lines(...), which re-enters the generic render pipeline and then splits/crops the rendered segments.Target:
Wrap the highlighted syntax
Textdirectly, then render and adjust each wrapped line for the configured width.Hypothesis:
Avoiding the generic
render_linespath should reduce overhead for large syntax blocks while preserving padding, styles, blank lines, trailing newlines, and line ranges.Target workload
User-visible operation:
Console.print(Syntax(...))for large word-wrapped Python syntax output without line numbers.Workload:
Environment:
Darwin Kernel Version 25.5.0Performance
Before, on #4178 tip before this change:
After:
This is about a 5.3% speedup for the target workload.
Correctness
I also checked output preservation for plain wrapped text, trailing newlines, blank middle lines, and
line_range, and smoke-tested the new ASV benchmark method:Tradeoffs
No cache or retained state. This duplicates the small part of
Console.render_lines(...)needed here: style application, fixed-width adjustment, and newline emission afterText.wrap(...).Stack
optimize-syntax-word-wrapmainperf/syntax-line-numbers-word-wrapperf/syntax-direct-word-wrap