Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 409cb77

Browse filesBrowse files
BridgeARmarco-ippolito
authored andcommitted
repl: fix cpu overhead pasting big strings to the REPL
Pasting input should not trigger any completions and other calculations. This is now handled by just writing the string to the terminal in case the user is pasting. As soon as pasting is done, the completions will be re-enabled. Fixes: #40626 Fixes: #43343 PR-URL: #59857 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d1c9d80 commit 409cb77
Copy full SHA for 409cb77

File tree

Expand file treeCollapse file tree

2 files changed

+42
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+42
-0
lines changed
Open diff view settings
Collapse file

‎lib/internal/readline/interface.js‎

Copy file name to clipboardExpand all lines: lib/internal/readline/interface.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,12 @@ class Interface extends InterfaceConstructor {
624624

625625
[kInsertString](c) {
626626
this[kBeforeEdit](this.line, this.cursor);
627+
if (!this.isCompletionEnabled) {
628+
this.line += c;
629+
this.cursor += c.length;
630+
this[kWriteToOutput](c);
631+
return;
632+
}
627633
if (this.cursor < this.line.length) {
628634
const beg = StringPrototypeSlice(this.line, 0, this.cursor);
629635
const end = StringPrototypeSlice(
Collapse file
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const repl = require('repl');
5+
const stream = require('stream');
6+
const assert = require('assert');
7+
8+
// Pasting big input should not cause the process to have a huge CPU usage.
9+
10+
const cpuUsage = process.cpuUsage();
11+
12+
const r = initRepl();
13+
r.input.emit('data', 'a'.repeat(2e4) + '\n');
14+
r.input.emit('data', '.exit\n');
15+
16+
r.once('exit', common.mustCall(() => {
17+
const diff = process.cpuUsage(cpuUsage);
18+
assert.ok(diff.user < 1e6);
19+
}));
20+
21+
function initRepl() {
22+
const input = new stream();
23+
input.write = input.pause = input.resume = () => {};
24+
input.readable = true;
25+
26+
const output = new stream();
27+
output.write = () => {};
28+
output.writable = true;
29+
30+
return repl.start({
31+
input,
32+
output,
33+
terminal: true,
34+
prompt: ''
35+
});
36+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.