Skip to content

repl: redraw highlighted input once per chunk - #67422

Open
maxhfisher wants to merge 1 commit into
nodejs:mainfrom
maxhfisher:repl-batch-highlight-redraw
Open

maxhfisher wants to merge 1 commit into
nodejs:mainfrom
maxhfisher:repl-batch-highlight-redraw

Conversation

@maxhfisher

@maxhfisher maxhfisher commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

This is intended as a fix for #67301. When text is pasted into the REPL, the terminal provides it in chunks, but readline interprets 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 readline to 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.

Issue's object (3,029 bytes, 161 lines) v24.15.0 (no highlighting) v26.13.0 (stock) v26.13.0 + fix
Bytes written to the terminal 4,941 7,426,597 435,541
Full redraws of the input 1 2,882 168

While working on this I noticed a separate bug (#67423 (comment)) on main which 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.

Signed-off-by: Max H Fisher <mfisher187@bloomberg.net>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module. repl Issues and PRs related to the REPL subsystem. labels Nov 11, 2026
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.71%. Comparing base (40aad9e) to head (a9858fe).
⚠️ Report is 41 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/readline/interface.js 92.68% 2 Missing and 1 partial ⚠️
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     
Files with missing lines Coverage Δ
lib/repl.js 92.97% <100.00%> (+0.03%) ⬆️
lib/internal/readline/interface.js 93.23% <92.68%> (-0.02%) ⬇️

... and 74 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module. repl Issues and PRs related to the REPL subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants