Render no-wrap syntax directly#4181
Open
KRRT7 wants to merge 5 commits into
Open
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4181 +/- ##
=======================================
Coverage ? 97.81%
=======================================
Files ? 96
Lines ? 8391
Branches ? 0
=======================================
Hits ? 8208
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 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=False, line_numbers=False)for non-transparent themes by rendering, cropping, and padding splitTextlines directly instead of routing the highlighted text throughConsole.render_lines(...).This stacks on #4179 and targets the remaining simple syntax rendering path that still used the generic
render_linespipeline.Performance framing
Observed:
The simple no-wrap, no-line-number syntax path still used
Console.render_lines(...)to crop and pad highlighted text.Target:
Split the highlighted
Textonce, render each line directly, and useSegment.adjust_line_length(...)with the line base style for padding.Hypothesis:
Avoiding the generic
render_linespath should reduce overhead for large syntax blocks while preserving crop, padding, blank-line, trailing-newline, and theme-background behavior.Target workload
User-visible operation:
Console.print(Syntax(...))for large Python syntax output without line wrapping or line numbers.Workload:
Environment:
Performance
Before, on #4179 tip before this change:
After:
This is about a 10.0% speedup for the target workload.
Correctness
I also checked output preservation for cropped lines, blank middle lines, and trailing newlines, and smoke-tested the new ASV benchmark method:
Tradeoffs
No new cache or retained state. This duplicates the small part of
Console.render_lines(...)needed for this hot path: rendering split text lines, applying the configured background style, fixed-width adjustment, and newline emission.Stack
optimize-syntax-word-wrapmainperf/syntax-line-numbers-word-wrapperf/syntax-direct-word-wrapperf/syntax-direct-no-wrap