From 856245f9170770fa974c62a674c6b738d4aab397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Louren=C3=A7o?= Date: Sun, 18 Jun 2023 16:41:49 -0300 Subject: [PATCH] draft: some exploration about performance of execSync --- lib/child_process.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/child_process.js b/lib/child_process.js index 59c37b97672d39..36a835f1c39652 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -91,6 +91,7 @@ const { ChildProcess, stdioStringToArray, } = child_process; +const perf_hooks = require('perf_hooks'); const MAX_BUFFER = 1024 * 1024; @@ -825,10 +826,13 @@ function spawn(file, args, options) { * }} */ function spawnSync(file, args, options) { + let now = perf_hooks.performance.now(); options = { maxBuffer: MAX_BUFFER, ...normalizeSpawnArguments(file, args, options), }; + console.log(`execSync spawnSync > normalizeSpawnArguments: ${perf_hooks.performance.now() - now}`); + now = perf_hooks.performance.now(); debug('spawnSync', options); @@ -838,9 +842,15 @@ function spawnSync(file, args, options) { // Validate maxBuffer, if present. validateMaxBuffer(options.maxBuffer); + console.log(`execSync spawnSync > validation: ${perf_hooks.performance.now() - now}`); + now = perf_hooks.performance.now(); + // Validate and translate the kill signal, if present. options.killSignal = sanitizeKillSignal(options.killSignal); + console.log(`execSync spawnSync > sanitizeKillSignal: ${perf_hooks.performance.now() - now}`); + now = perf_hooks.performance.now(); + options.stdio = getValidStdio(options.stdio || 'pipe', true).stdio; if (options.input) { @@ -868,7 +878,12 @@ function spawnSync(file, args, options) { } } - return child_process.spawnSync(options); + console.log(`execSync spawnSync > stdio & input: ${perf_hooks.performance.now() - now}`); + now = perf_hooks.performance.now(); + const result = child_process.spawnSync(options); + console.log(`execSync spawnSync > child_process.spawnSync: ${perf_hooks.performance.now() - now}`); + + return result; } @@ -946,16 +961,27 @@ function execFileSync(file, args, options) { * @returns {Buffer | string} */ function execSync(command, options) { + let now = perf_hooks.performance.now(); const opts = normalizeExecArgs(command, options, null); + console.log(`execSync normalizeExecArgs: ${perf_hooks.performance.now() - now}`); + now = perf_hooks.performance.now(); const inheritStderr = !opts.options.stdio; const ret = spawnSync(opts.file, opts.options); + console.log(`execSync spawnSync: ${perf_hooks.performance.now() - now}`); + now = perf_hooks.performance.now(); if (inheritStderr && ret.stderr) process.stderr.write(ret.stderr); + console.log(`execSync inheritStderr: ${perf_hooks.performance.now() - now}`); + now = perf_hooks.performance.now(); + const err = checkExecSyncError(ret, undefined, command); + console.log(`execSync checkExecSyncError: ${perf_hooks.performance.now() - now}`); + now = perf_hooks.performance.now(); + if (err) throw err;