Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process: add fast path for spawn #57196

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

ronag
Copy link
Member

@ronag ronag commented Feb 24, 2025

No description provided.

@nodejs-github-bot nodejs-github-bot added child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run. labels Feb 24, 2025
@ronag
Copy link
Member Author

ronag commented Feb 24, 2025

@ronag
Copy link
Member Author

ronag commented Feb 25, 2025

Unrelated CI benchmark failure...

10:42:39 ../src/node_config_file.h:35:32: error: ‘simdjson’ has not been declared
10:42:39    35 |   ParseResult ParseNodeOptions(simdjson::ondemand::object* node_options_object);
10:42:39       |                                ^~~~~~~~
10:42:39 ../src/node_config_file.h:35:58: error: expected ‘,’ or ‘...’ before ‘*’ token
10:42:39    35 |   ParseResult ParseNodeOptions(simdjson::ondemand::object* node_options_object);
10:42:39       |                                                          ^
10:42:39 make[1]: *** [libnode.target.mk:510: /w/bnch-comp/node/out/Release/obj.target/libnode/src/node.o] Error 1

Who's a good ping on that? @nodejs/benchmarking

@atlowChemi
Copy link
Member

ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1661

https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1662/

                                   confidence improvement accuracy (*)   (**)  (***)
child_process/spawn-echo.js n=1000        ***     16.87 %       ±1.27% ±1.69% ±2.21%

Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case, there are 1 comparisons, you can thus
expect the following amount of false-positive results:
  0.05 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.01 false positives, when considering a   1% risk acceptance (**, ***),
  0.00 false positives, when considering a 0.1% risk acceptance (***)

@atlowChemi atlowChemi added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 25, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 25, 2025
@aduh95
Copy link
Contributor

aduh95 commented Feb 25, 2025

nit: I find the commit message a bit confusing, our guidelines asks for the first word to be an imperative verb, which "spawn" is, but is not used as such here. My suggestion would be child_process: add fast path for `spawn`

@nodejs-github-bot
Copy link
Collaborator

@ronag ronag changed the title child_process: spawn fast path child_process: add fast path for spawn Feb 25, 2025
@ronag
Copy link
Member Author

ronag commented Feb 25, 2025

I have to admit I don't actually understand what normalizeSpawnArguments does in terms of the env variables... seems a bit suspect.

@ronag
Copy link
Member Author

ronag commented Feb 25, 2025

In particular what does this do? Seems to always process process.env. Which seems rather wasteful?

  const env = options.env || process.env;
  const envPairs = [];

  // process.env.NODE_V8_COVERAGE always propagates, making it possible to
  // collect coverage for programs that spawn with white-listed environment.
  copyProcessEnvToEnv(env, 'NODE_V8_COVERAGE', options.env);

  if (isZOS) {
    // The following environment variables must always propagate if set.
    copyProcessEnvToEnv(env, '_BPXK_AUTOCVT', options.env);
    copyProcessEnvToEnv(env, '_CEE_RUNOPTS', options.env);
    copyProcessEnvToEnv(env, '_TAG_REDIR_ERR', options.env);
    copyProcessEnvToEnv(env, '_TAG_REDIR_IN', options.env);
    copyProcessEnvToEnv(env, '_TAG_REDIR_OUT', options.env);
    copyProcessEnvToEnv(env, 'STEPLIB', options.env);
    copyProcessEnvToEnv(env, 'LIBPATH', options.env);
    copyProcessEnvToEnv(env, '_EDC_SIG_DFLT', options.env);
    copyProcessEnvToEnv(env, '_EDC_SUSV3', options.env);
  }

  let envKeys = [];
  // Prototype values are intentionally included.
  for (const key in env) {
    ArrayPrototypePush(envKeys, key);
  }

  if (process.platform === 'win32') {
    // On Windows env keys are case insensitive. Filter out duplicates,
    // keeping only the first one (in lexicographic order)
    const sawKey = new SafeSet();
    envKeys = ArrayPrototypeFilter(
      ArrayPrototypeSort(envKeys),
      (key) => {
        const uppercaseKey = StringPrototypeToUpperCase(key);
        if (sawKey.has(uppercaseKey)) {
          return false;
        }
        sawKey.add(uppercaseKey);
        return true;
      },
    );
  }

  for (const key of envKeys) {
    const value = env[key];
    if (value !== undefined) {
      validateArgumentNullCheck(key, `options.env['${key}']`);
      validateArgumentNullCheck(value, `options.env['${key}']`);
      ArrayPrototypePush(envPairs, `${key}=${value}`);
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants