Skip to content

Commit 19b298a

Browse files
build,win: limit LTO parallelisation for releases
1 parent 01ef499 commit 19b298a

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

common.gypi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,13 @@
272272
},
273273
},
274274
},],
275+
['(enable_thin_lto=="true" or enable_lto=="true") and lto_jobs!=""', {
276+
'msvs_settings': {
277+
'VCLinkerTool': {
278+
'AdditionalOptions': ['/opt:lldltojobs=<(lto_jobs)'],
279+
},
280+
},
281+
},],
275282
],
276283
'target_conditions': [
277284
['_toolset=="target"', {

configure.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@
225225
help="Enable compiling with thin lto of a binary. This feature is only available "
226226
"on windows.")
227227

228+
parser.add_argument("--lto-jobs",
229+
action="store",
230+
dest="lto_jobs",
231+
default=None,
232+
help="Set the number of parallel LTO code generation jobs during linking. "
233+
"Defaults to the number of CPU cores. Lower values reduce peak memory "
234+
"usage at the cost of longer link times. Only effective with LTO enabled.")
235+
228236
parser.add_argument("--link-module",
229237
action="append",
230238
dest="linked_module",
@@ -2001,6 +2009,7 @@ def configure_node(o):
20012009

20022010
o['variables']['enable_lto'] = b(options.enable_lto)
20032011
o['variables']['enable_thin_lto'] = b(options.enable_thin_lto)
2012+
o['variables']['lto_jobs'] = options.lto_jobs or ''
20042013

20052014
if options.node_use_large_pages or options.node_use_large_pages_script_lld:
20062015
warn('''The `--use-largepages` and `--use-largepages-script-lld` options

vcbuild.bat

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ set target_arch=x64
2626
set ltcg=
2727
set thin_lto=
2828
set lto=
29+
set lto_jobs=
2930
set pgo_generate=
3031
set pgo_use=
3132
set target_env=
@@ -110,6 +111,7 @@ if /i "%1"=="nonpm" set nonpm=1&goto arg-ok
110111
if /i "%1"=="ltcg" set ltcg=1&goto arg-ok
111112
if /i "%1"=="thin-lto" set thin_lto=1&goto arg-ok
112113
if /i "%1"=="lto" set lto=1&goto arg-ok
114+
if /i "%1"=="lto-jobs" set "lto_jobs=%2"&goto arg-ok-2
113115
if /i "%1"=="pgo-generate" set pgo_generate=1&goto arg-ok
114116
if /i "%1"=="pgo-use" set pgo_use=1&goto arg-ok
115117
if /i "%1"=="v8temporal" set v8temporal=1&goto arg-ok
@@ -197,6 +199,8 @@ if defined build_release (
197199
set projgen=1
198200
set cctest=1
199201
set thin_lto=1
202+
@REM Parallel LTO link jobs can cause OOM issues, so we limit it to 2 by default for release builds in the release CI.
203+
set lto_jobs=2
200204
)
201205

202206
:: LTO mutual exclusion
@@ -243,6 +247,7 @@ if defined nonpm set configure_flags=%configure_flags% --without-npm
243247
if defined ltcg set configure_flags=%configure_flags% --with-ltcg
244248
if defined thin_lto set configure_flags=%configure_flags% --enable-thin-lto
245249
if defined lto set configure_flags=%configure_flags% --enable-lto
250+
if defined lto_jobs set configure_flags=%configure_flags% --lto-jobs=%lto_jobs%
246251
if defined pgo_generate set configure_flags=%configure_flags% --enable-pgo-generate
247252
if defined pgo_use set configure_flags=%configure_flags% --enable-pgo-use
248253
if defined release_urlbase set configure_flags=%configure_flags% --release-urlbase=%release_urlbase%
@@ -908,7 +913,7 @@ set exit_code=1
908913
goto exit
909914

910915
:help
911-
echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-internet/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [build-addons/build-js-native-api-tests/build-node-api-tests/build-ffi-tests] [ignore-flaky] [static/dll] [noprojgen] [projgen] [clang-cl] [ccache path-to-ccache] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [nonpm] [ltcg] [thin-lto] [lto] [pgo-generate] [pgo-use] [licensetf] [sign] [x64/arm64] [vs2022/vs2026] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [format-md] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm]
916+
echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-internet/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [build-addons/build-js-native-api-tests/build-node-api-tests/build-ffi-tests] [ignore-flaky] [static/dll] [noprojgen] [projgen] [clang-cl] [ccache path-to-ccache] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [nonpm] [ltcg] [thin-lto] [lto] [lto-jobs number-of-jobs] [pgo-generate] [pgo-use] [licensetf] [sign] [x64/arm64] [vs2022/vs2026] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [format-md] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm]
912917
echo Examples:
913918
echo vcbuild.bat : builds release build
914919
echo vcbuild.bat debug : builds debug build
@@ -922,6 +927,7 @@ echo vcbuild.bat no-cctest : skip building cctest.exe
922927
echo vcbuild.bat ccache c:\ccache\ : use ccache to speed build
923928
echo vcbuild.bat thin-lto : builds with Thin LTO applied globally to all targets
924929
echo vcbuild.bat lto : builds with Full LTO applied globally to all targets
930+
echo vcbuild.bat thin-lto lto-jobs 2 : builds with Thin LTO applied globally to all targets and limits parallel LTO link jobs (reduces peak memory usage)
925931
echo vcbuild.bat pgo-generate : builds instrumented binary for PGO (profile first, then rebuild with pgo-use)
926932
echo vcbuild.bat pgo-use : builds optimized binary using PGO profile data
927933
goto exit

0 commit comments

Comments
 (0)