Repository navigation
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:
|
UnderHear
left a comment
There was a problem hiding this comment.
AI-assisted source review using OpenAI Codex; I have not run the tests.
Could this direct path preserve the requested overflow mode before cropping the segments? For example, console.print(Syntax('abcdefgh', 'text', word_wrap=False, line_numbers=False), width=5, overflow='ellipsis') previously renders abcd…, because Text.__rich_console__ passes options.overflow to Text.wrap/truncate. Here line.render(console) bypasses that step and Segment.adjust_line_length only crops, so it produces abcde instead. The transparent-theme branch still uses console.render and retains the ellipsis behavior.
Please retain the ellipsis truncation for this fast path and add an opaque-theme regression for a long line with overflow='ellipsis'.
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