Repository navigation
repl: redraw highlighted input once per chunk - #67422
maxhfisher wants to merge 2 commits into
Conversation
Signed-off-by: Max H Fisher <mfisher187@bloomberg.net>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #67422 +/- ##
==========================================
- Coverage 90.72% 90.71% -0.02%
==========================================
Files 798 801 +3
Lines 280074 281922 +1848
Branches 53876 54323 +447
==========================================
+ Hits 254101 255737 +1636
- Misses 16272 16309 +37
- Partials 9701 9876 +175
🚀 New features to boost your workflow:
|
|
@maxhfisher The final-character path appears to redraw the input twice. "emitKeypressEvents()" leaves "isCompletionEnabled" true for the last character in a chunk, so "kWillDeferRefresh()" returns false. This flushes the pending redraw at the start of "kTtyWrite()", before the final character is inserted. The normal insertion path then calls "kRefreshLine()" again. As a result, a highlighted paste with multiple characters redraws twice at the end of each chunk, rather than once as intended. Could the final keypress consume the pending refresh instead of flushing it before dispatch? A regression test that counts full redraws for a multi-character chunk would catch this; the current test checks final rendering but not redraw count. |
@ViviBeri This is true, although the cost is quite minimal. I ran an experiment with a fix for this and it saved 2 redraws and about 5KB of I've added this change to the PR. I (or I should say an agentic reviewer I was using) noticed that when the last character of a paste is a tab, the current behavior is to treat that tab as a real keypress and provide the autocompletion behavior. No test actually asserts that for the case where
I intentionally chose not to add a test which asserts on the number of redraws because I didn't think that should be part of the contract. This is just a performance optimization, so I don't think we should make promises about the implementation. If maintainers feel strongly that this is worth asserting on, I'm happy to add it. |
This is intended as a fix for #67301. When text is pasted into the REPL, the terminal provides it in chunks, but
readlineinterprets and redraws the entire input for each character when syntax highlighting is enabled (#64591). When the pasted text is large, this makes the REPL feel noticeably slow.This changes
readlineto only redraw when a pasted chunk has been processed or if there is a character in the text that requires the screen to be up to date (such as a return or backspace). This reduces the number of full redraws and output as shown in the table below. However, the total number of bytes written to the terminal still grows quadratically with the number of lines. This only improves performance by a constant multiple for multi-line pastes.While working on this I noticed a separate bug (#67423 (comment)) on
mainwhich wasn't back-ported to v26 that causes large multi-line pastes to be truncated. To test this fix, you'll need to build it on top of v26.