From 111d7c2f40298a965c7f6df632789d1ac3e81fb4 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 18 Jun 2026 10:29:53 -0400 Subject: [PATCH] src: run node --run scripts without a subshell node --run previously spawned the script's command through /bin/sh and kept the (large) node process resident to wait for the child, then went through the normal process shutdown. For a launcher that never initializes V8/JS this is mostly wasted work: forking the node process, an event-loop round-trip and tearing down V8/ICU/OpenSSL static state. On POSIX, replace this with a direct hand-off: - Simple commands (a plain `program args` invocation with no shell metacharacters) are executed directly with execvp(), bypassing the shell entirely. Positional arguments are passed through verbatim. - Anything that needs shell syntax execve()s /bin/sh, still replacing the node process instead of forking a child and waiting for it. - If the exec fails (e.g. the command is a shell builtin or is not found) it falls back to the original uv_spawn() path. ICU initialization is skipped for --run as well, since the Intl APIs are never reached. Because node now execs the target directly, the script's exact exit status is propagated instead of being collapsed to 1. Benchmarks on macOS for `node --run` of a node_modules/.bin binary show roughly a 1.4x reduction in wall-clock time versus the previous shell spawn. Windows keeps the existing spawn-based behavior. Signed-off-by: Yagiz Nizipli Co-authored-by: Cursor --- src/node.cc | 17 ++++++- src/node_task_runner.cc | 108 +++++++++++++++++++++++++++++++++++++++- src/node_task_runner.h | 7 +++ 3 files changed, 129 insertions(+), 3 deletions(-) diff --git a/src/node.cc b/src/node.cc index 4ba019ddca05f4..bf356438c9f5bd 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1000,7 +1000,12 @@ static ExitCode InitializeNodeWithArgsInternal( uv_set_process_title(per_process::cli_options->title.c_str()); #if defined(NODE_HAVE_I18N_SUPPORT) - if (!(flags & ProcessInitializationFlags::kNoICU)) { + // The `node --run