mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
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: https://github.com/nodejs/node/issues/40626 Fixes: https://github.com/nodejs/node/issues/43343 PR-URL: https://github.com/nodejs/node/pull/59857 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
d079d8f380
commit
49f79b8e93
|
|
@ -658,6 +658,12 @@ class Interface extends InterfaceConstructor {
|
||||||
|
|
||||||
[kInsertString](c) {
|
[kInsertString](c) {
|
||||||
this[kBeforeEdit](this.line, this.cursor);
|
this[kBeforeEdit](this.line, this.cursor);
|
||||||
|
if (!this.isCompletionEnabled) {
|
||||||
|
this.line += c;
|
||||||
|
this.cursor += c.length;
|
||||||
|
this[kWriteToOutput](c);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this.cursor < this.line.length) {
|
if (this.cursor < this.line.length) {
|
||||||
const beg = StringPrototypeSlice(this.line, 0, this.cursor);
|
const beg = StringPrototypeSlice(this.line, 0, this.cursor);
|
||||||
const end = StringPrototypeSlice(
|
const end = StringPrototypeSlice(
|
||||||
|
|
|
||||||
36
test/parallel/test-repl-paste-big-data.js
Normal file
36
test/parallel/test-repl-paste-big-data.js
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const common = require('../common');
|
||||||
|
const repl = require('repl');
|
||||||
|
const stream = require('stream');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
// Pasting big input should not cause the process to have a huge CPU usage.
|
||||||
|
|
||||||
|
const cpuUsage = process.cpuUsage();
|
||||||
|
|
||||||
|
const r = initRepl();
|
||||||
|
r.input.emit('data', 'a'.repeat(2e4) + '\n');
|
||||||
|
r.input.emit('data', '.exit\n');
|
||||||
|
|
||||||
|
r.once('exit', common.mustCall(() => {
|
||||||
|
const diff = process.cpuUsage(cpuUsage);
|
||||||
|
assert.ok(diff.user < 1e6);
|
||||||
|
}));
|
||||||
|
|
||||||
|
function initRepl() {
|
||||||
|
const input = new stream();
|
||||||
|
input.write = input.pause = input.resume = () => {};
|
||||||
|
input.readable = true;
|
||||||
|
|
||||||
|
const output = new stream();
|
||||||
|
output.write = () => {};
|
||||||
|
output.writable = true;
|
||||||
|
|
||||||
|
return repl.start({
|
||||||
|
input,
|
||||||
|
output,
|
||||||
|
terminal: true,
|
||||||
|
prompt: ''
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user