Skip to content

Commit

Permalink
child_process: improve spawn performance on Linux
Browse files Browse the repository at this point in the history
Speed up child_process.spawn by enabling the new V8 build flag which
makes fork/exec faster.

Here are the results of running the existing benchmark. Note that this
optimization helps more for applications with larger heaps, so this is
somewhat of an underestimate of the real world performance benefits.

```console
$ ./node benchmark/compare.js --runs 15 \
        --new ./node \
        --old ~/node-v20/out/Release/node \
        --filter params child_process > cpr
$ node-benchmark-compare cpr
                                 confidence improvement  (***)
methodName='exec' n=1000                ***     60.84 % ±5.43%
methodName='execFile' n=1000            ***     53.72 % ±3.33%
methodName='execFileSync' n=1000        ***      9.10 % ±0.84%
methodName='execSync' n=1000            ***     10.44 % ±0.97%
methodName='spawn' n=1000               ***     53.10 % ±2.90%
methodName='spawnSync' n=1000           ***      8.64 % ±1.22%

  0.01 false positives, when considering a 0.1% risk acceptance (***)
```

Fixes: nodejs#25382
Fixes: nodejs#14917
Refs: nodejs/performance#93
Refs: nodejs/performance#89
PR-URL: nodejs#48523
Refs: v8/v8@1a782f6
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Debadree Chatterjee <[email protected]>
  • Loading branch information
kvakil authored and aduh95 committed Oct 9, 2023
1 parent f68d5e5 commit b9c294b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tools/v8_gypfiles/features.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@
}, {
'v8_enable_system_instrumentation': 0,
}],
['OS=="linux"', {
# Sets -dV8_ENABLE_PRIVATE_MAPPING_FORK_OPTIMIZATION.
#
# This flag speeds up the performance of fork/execve on Linux systems for
# embedders which use it (like Node.js). It works by marking the pages that
# V8 allocates as MADV_DONTFORK. Without MADV_DONTFORK, the Linux kernel
# spends a long time manipulating page mappings on fork and exec which the
# child process doesn't generally need to access.
#
# See v8:7381 for more details.
'v8_enable_private_mapping_fork_optimization': 1,
}, {
'v8_enable_private_mapping_fork_optimization': 0,
}],
],
'is_debug%': 0,

Expand Down Expand Up @@ -310,6 +324,9 @@
['v8_enable_hugepage==1', {
'defines': ['ENABLE_HUGEPAGE',],
}],
['v8_enable_private_mapping_fork_optimization==1', {
'defines': ['V8_ENABLE_PRIVATE_MAPPING_FORK_OPTIMIZATION'],
}],
['v8_enable_vtunejit==1', {
'defines': ['ENABLE_VTUNE_JIT_INTERFACE',],
}],
Expand Down

0 comments on commit b9c294b

Please sign in to comment.