Skip to content

Commit 99a96e0

Browse files
committed
child_process: improve spawn performance on Linux
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: #25382 Fixes: #14917 Refs: nodejs/performance#93 Refs: nodejs/performance#89
1 parent 464e319 commit 99a96e0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tools/v8_gypfiles/features.gypi

+14
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@
111111
# Sets -dENABLE_HUGEPAGE
112112
'v8_enable_hugepage%': 0,
113113

114+
# Sets -dV8_ENABLE_PRIVATE_MAPPING_FORK_OPTIMIZATION.
115+
#
116+
# This flag speeds up the performance of fork/execve on Linux systems for
117+
# embedders which use it (like Node.js). It works by marking the pages that
118+
# V8 allocates as MADV_DONTFORK. Without MADV_DONTFORK, the Linux kernel
119+
# spends a long time manipulating page mappings on fork and exec which the
120+
# child process doesn't generally need to access.
121+
#
122+
# See v8:7381 for more details.
123+
'v8_enable_private_mapping_fork_optimization%': 1,
124+
114125
# Sets -dENABLE_VTUNE_JIT_INTERFACE.
115126
'v8_enable_vtunejit%': 0,
116127

@@ -320,6 +331,9 @@
320331
['v8_enable_hugepage==1', {
321332
'defines': ['ENABLE_HUGEPAGE',],
322333
}],
334+
['v8_enable_private_mapping_fork_optimization==1', {
335+
'defines': ['V8_ENABLE_PRIVATE_MAPPING_FORK_OPTIMIZATION'],
336+
}],
323337
['v8_enable_vtunejit==1', {
324338
'defines': ['ENABLE_VTUNE_JIT_INTERFACE',],
325339
}],

0 commit comments

Comments
 (0)