Files
node/benchmark/readline/readline-createInterface.js
T
Matteo Collina 9041ad047a readline: reduce createInterface overhead
Speed up Interface construction:

- Hoist the history accessor property descriptors to module scope and
  define them with a single ObjectDefineProperties call, instead of
  allocating six closures and four descriptor objects per instance.
- Stop assigning the history options onto the input stream. This avoids
  hidden class transitions on the user provided stream and no longer
  mutates it observably.
- Only check process.env.TERM for a dumb terminal when the interface is
  in terminal mode. Reading process.env goes through the environment
  interceptor and is comparatively expensive, and _ttyWrite is never
  called when terminal is false.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/64585
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-07-24 09:09:01 -07:00

27 lines
601 B
JavaScript

'use strict';
const common = require('../common.js');
const readline = require('readline');
const { Readable, Writable } = require('stream');
const bench = common.createBenchmark(main, {
n: [1e5],
terminal: [0, 1],
});
function main({ n, terminal }) {
bench.start();
for (let i = 0; i < n; i++) {
const input = new Readable({ read() {} });
const output = new Writable({ write(chunk, encoding, callback) {
callback();
} });
const rl = readline.createInterface({
input,
output,
terminal: Boolean(terminal),
});
rl.close();
}
bench.end(n);
}