Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
build,win: enable x64 PGO
  • Loading branch information
StefanStojanovic committed Apr 15, 2026
commit 21eb097e524b991f36ccdbec55caeef3a3a8304c
24 changes: 24 additions & 0 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,30 @@
},],
],
},],
['OS=="win"', {
'conditions': [
['enable_pgo_generate=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fprofile-generate'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fprofile-generate'],
},
},
},],
['enable_pgo_use=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-fprofile-use=$(SolutionDir)node.profdata'],
},
'VCLinkerTool': {
'AdditionalOptions': ['-fprofile-use=$(SolutionDir)node.profdata'],
},
},
},],
],
},],
['OS == "android"', {
'cflags': [ '-fPIC', '-I<(android_ndk_path)/sources/android/cpufeatures' ],
'ldflags': [ '-fPIC' ]
Expand Down
25 changes: 15 additions & 10 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@
dest="enable_pgo_generate",
default=None,
help="Enable profiling with pgo of a binary. This feature is only available "
"on linux with gcc and g++ 5.4.1 or newer.")
"on linux with gcc and g++ 5.4.1 or newer and on windows.")

parser.add_argument("--enable-pgo-use",
action="store_true",
dest="enable_pgo_use",
default=None,
help="Enable use of the profile generated with --enable-pgo-generate. This "
"feature is only available on linux with gcc and g++ 5.4.1 or newer.")
"feature is only available on linux with gcc and g++ 5.4.1 or newer and on windows.")

parser.add_argument("--enable-lto",
action="store_true",
Expand Down Expand Up @@ -1909,9 +1909,9 @@ def configure_node(o):
else:
o['variables']['node_enable_v8_vtunejit'] = 'false'

if flavor != 'linux' and (options.enable_pgo_generate or options.enable_pgo_use):
if (flavor != 'linux' and flavor != 'win') and (options.enable_pgo_generate or options.enable_pgo_use):
raise Exception(
'The pgo option is supported only on linux.')
'The pgo option is supported only on linux and windows.')

if flavor == 'linux':
if options.enable_pgo_generate or options.enable_pgo_use:
Expand All @@ -1922,12 +1922,17 @@ def configure_node(o):
'The options --enable-pgo-generate and --enable-pgo-use '
f'are supported for gcc and gxx {version_checked_str} or newer only.')

if options.enable_pgo_generate and options.enable_pgo_use:
raise Exception(
'Only one of the --enable-pgo-generate or --enable-pgo-use options '
'can be specified at a time. You would like to use '
'--enable-pgo-generate first, profile node, and then recompile '
'with --enable-pgo-use')
if options.enable_pgo_generate and options.enable_pgo_use:
raise Exception(
'Only one of the --enable-pgo-generate or --enable-pgo-use options '
'can be specified at a time. You would like to use '
'--enable-pgo-generate first, profile node, and then recompile '
'with --enable-pgo-use')

if flavor == 'win' and options.with_ltcg and (options.enable_pgo_generate or options.enable_pgo_use):
raise Exception(
'The --with-ltcg option cannot be used with --enable-pgo-generate or --enable-pgo-use. '
'PGO uses /LTCG:PGInstrument or /LTCG:PGOptimize while LTCG uses /LTCG:INCREMENTAL.')

o['variables']['enable_pgo_generate'] = b(options.enable_pgo_generate)
o['variables']['enable_pgo_use'] = b(options.enable_pgo_use)
Expand Down
32 changes: 21 additions & 11 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -730,25 +730,35 @@
'Ws2_32.lib',
],
}],
['node_with_ltcg=="true"', {
# Whole-program optimization: either LTCG or PGO
['node_with_ltcg=="true" or enable_pgo_generate=="true" or enable_pgo_use=="true"', {
'msvs_settings': {
'VCCLCompilerTool': {
'WholeProgramOptimization': 'true' # /GL, whole program optimization, needed for LTCG
},
'VCLibrarianTool': {
'AdditionalOptions': [
'/LTCG:INCREMENTAL', # link time code generation
],
'WholeProgramOptimization': 'true' # /GL, whole program optimization, needed for both LTCG and PGO
},
'VCLinkerTool': {
'OptimizeReferences': 2, # /OPT:REF
'EnableCOMDATFolding': 2, # /OPT:ICF
'LinkIncremental': 1, # disable incremental linking
'AdditionalOptions': [
'/LTCG:INCREMENTAL', # incremental link-time code generation
],
}
}
},
'conditions': [
# LTCG-specific settings (only when PGO not active)
['node_with_ltcg=="true" and enable_pgo_generate!="true" and enable_pgo_use!="true"', {
'msvs_settings': {
'VCLibrarianTool': {
'AdditionalOptions': [
'/LTCG:INCREMENTAL', # link time code generation
],
},
'VCLinkerTool': {
'AdditionalOptions': [
'/LTCG:INCREMENTAL', # incremental link-time code generation
],
},
},
}],
]
}, {
'msvs_settings': {
'VCCLCompilerTool': {
Expand Down
18 changes: 17 additions & 1 deletion vcbuild.bat
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ set config=Release
set target=Build
set target_arch=x64
set ltcg=
set pgo_generate=
set pgo_use=
set target_env=
set noprojgen=
set projgen=
Expand Down Expand Up @@ -104,6 +106,8 @@ if /i "%1"=="sign" set sign=1&goto arg-ok
if /i "%1"=="nosnapshot" set nosnapshot=1&goto arg-ok
if /i "%1"=="nonpm" set nonpm=1&goto arg-ok
if /i "%1"=="ltcg" set ltcg=1&goto arg-ok
if /i "%1"=="pgo-generate" set pgo_generate=1&goto arg-ok
if /i "%1"=="pgo-use" set pgo_use=1&goto arg-ok
if /i "%1"=="v8temporal" set v8temporal=1&goto arg-ok
if /i "%1"=="v8windbg" set v8windbg=1&goto arg-ok
if /i "%1"=="licensertf" set licensertf=1&goto arg-ok
Expand Down Expand Up @@ -179,6 +183,14 @@ goto next-arg

:args-done

:: PGO mutual exclusion
if defined pgo_generate if defined pgo_use (
echo Error: Only one of 'pgo-generate' or 'pgo-use' can be specified.
echo pgo-generate : build instrumented binary, then profile it
echo pgo-use : rebuild using the collected profile data
exit /b 1
)

if defined build_release (
set config=Release
set package=1
Expand Down Expand Up @@ -212,6 +224,8 @@ if "%config%"=="Debug" set configure_flags=%configure_flags% --debug
if defined nosnapshot set configure_flags=%configure_flags% --without-snapshot
if defined nonpm set configure_flags=%configure_flags% --without-npm
if defined ltcg set configure_flags=%configure_flags% --with-ltcg
if defined pgo_generate set configure_flags=%configure_flags% --enable-pgo-generate
if defined pgo_use set configure_flags=%configure_flags% --enable-pgo-use
if defined release_urlbase set configure_flags=%configure_flags% --release-urlbase=%release_urlbase%
if defined download_arg set configure_flags=%configure_flags% %download_arg%
if defined enable_vtune_arg set configure_flags=%configure_flags% --enable-vtune-profiling
Expand Down Expand Up @@ -875,7 +889,7 @@ set exit_code=1
goto exit

:help
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] [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]
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] [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]
echo Examples:
echo vcbuild.bat : builds release build
echo vcbuild.bat debug : builds debug build
Expand All @@ -887,6 +901,8 @@ echo vcbuild.bat link-module my_module.js : bundles my_module as built-in modu
echo vcbuild.bat lint : runs the C++, documentation and JavaScript linter
echo vcbuild.bat no-cctest : skip building cctest.exe
echo vcbuild.bat ccache c:\ccache\ : use ccache to speed build
echo vcbuild.bat pgo-generate : builds instrumented binary for PGO (profile first, then rebuild with pgo-use)
echo vcbuild.bat pgo-use : builds optimized binary using PGO profile data
goto exit

:exit
Expand Down