From 67a494bd3be6818f9f78c535fb01737a340485a1 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 24 Feb 2025 16:39:44 +0100 Subject: [PATCH 1/2] child_process: add fast path for `spawn` PR-URL: https://github.com/nodejs/node/pull/57196 --- lib/child_process.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/child_process.js b/lib/child_process.js index 3fb21f755be3d7..0e04e49880289f 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -743,6 +743,20 @@ function abortChildProcess(child, killSignal, reason) { * @returns {ChildProcess} */ function spawn(file, args, options) { + if (options == null && ArrayIsArray(args) && typeof file === 'string' && !StringPrototypeIncludes(file, '\u0000')) { + const child = new ChildProcess(); + options = { + args, + detached: false, + file, + windowsHide: false, + windowsVerbatimArguments: false, + }; + debug('spawn', options); + child.spawn(options); + return child; + } + options = normalizeSpawnArguments(file, args, options); validateTimeout(options.timeout); validateAbortSignal(options.signal, 'options.signal'); From d41914b63aacb5761fb12559ae7f7fde1a94f7df Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 25 Feb 2025 20:25:09 +0100 Subject: [PATCH 2/2] WIP --- lib/child_process.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 0e04e49880289f..1afd5406af9fc7 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -743,10 +743,17 @@ function abortChildProcess(child, killSignal, reason) { * @returns {ChildProcess} */ function spawn(file, args, options) { - if (options == null && ArrayIsArray(args) && typeof file === 'string' && !StringPrototypeIncludes(file, '\u0000')) { + if ( + options == null && + ArrayIsArray(args) && + typeof file === 'string' && + file.length > 0 && + !StringPrototypeIncludes(file, '\u0000') && + !isZOS + ) { const child = new ChildProcess(); options = { - args, + args: [file, ...args], detached: false, file, windowsHide: false,