Skip hidden line-range syntax prefix text#4182
Open
KRRT7 wants to merge 6 commits into
Open
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4182 +/- ##
=======================================
Coverage ? 97.81%
=======================================
Files ? 96
Lines ? 8392
Branches ? 0
=======================================
Hits ? 8209
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.
Workload
Render a large Python
Syntaxobject with a lateline_rangeand no wrapping or line numbers:PYTHONPATH=. uvx --with pytest-benchmark pytest /tmp/rich_pytest_bench_syntax.py --benchmark-only --benchmark-min-rounds=15 --benchmark-max-time=1 --benchmark-cprofile=cumtime --benchmark-cprofile-top=15 --benchmark-columns="min,median,mean,rounds,iterations"Input:
snippets.PYTHON_SNIPPET * 120,lexer="python",word_wrap=False,line_numbers=False,line_range=(3000, 3060), width 80.This matters for callers that render only a small late slice of a large highlighted source file.
Results
Before, at
6d54cb8d:test_highlight_line_range_3000: 65.1610 ms median over 15 roundstest_render_line_range_3000: 71.1404 ms median over 15 roundsAfter, at
06406dd2:test_highlight_line_range_3000: 62.9820 ms median over 15 roundstest_render_line_range_3000: 68.3597 ms median over 15 roundsThe pytest-benchmark cProfile output shows the previous path spent extra time in
Text.append_tokensappending skipped prefix tokens before the requested range. The new path still tokenizes the prefix so lexer state is preserved, but emits only newline placeholders for skipped lines.Correctness
python3 -m pytest tests/test_syntax.py tests/test_console.pyuvx black --check rich/syntax.py benchmarks/benchmarks.py tests/test_syntax.pyTradeoffs
No behavior change intended. Late line ranges still tokenize from the beginning of the source to keep Pygments lexer state correct. This only avoids storing the skipped source text in the intermediate
Text.Stack
optimize-syntax-word-wrapperf/syntax-line-numbers-word-wrapperf/syntax-direct-word-wrapperf/syntax-direct-no-wrapperf/syntax-line-range-skip-prefix