chore: optimize release builds for speed (#3735) (#3777)

* Add -flto (lto_incremental, link-time optimization) for release builds
* Add -s (strip symbols) for release builds
* Switch library builds from --opt:size to --opt:speed
* Change -d:marchOptimized to x86-64-v2 target from broadwell
* Remove obsolete chronicles_colors=off for Windows
* Remove obsolete withoutPCRE define
This commit is contained in:
Fabiana Cecin 2026-04-02 07:10:02 -03:00 committed by Ivan FB
parent f3852c3a43
commit 2dac0866f1
No known key found for this signature in database
GPG Key ID: DF0C67A04C543270
3 changed files with 9 additions and 13 deletions

View File

@ -134,7 +134,7 @@ deps: | deps-common nat-libs waku.nims
# "-d:release" implies "--stacktrace:off" and it cannot be added to config.nims
ifeq ($(DEBUG), 0)
NIM_PARAMS := $(NIM_PARAMS) -d:release
NIM_PARAMS := $(NIM_PARAMS) -d:release -d:lto_incremental -d:strip
else
NIM_PARAMS := $(NIM_PARAMS) -d:debug
endif

View File

@ -26,10 +26,6 @@ if defined(windows):
# set the IMAGE_FILE_LARGE_ADDRESS_AWARE flag so we can use PAE, if enabled, and access more than 2 GiB of RAM
switch("passL", "-Wl,--large-address-aware")
# The dynamic Chronicles output currently prevents us from using colors on Windows
# because these require direct manipulations of the stdout File object.
switch("define", "chronicles_colors=off")
# https://github.com/status-im/nimbus-eth2/blob/stable/docs/cpu_features.md#ssse3-supplemental-sse3
# suggests that SHA256 hashing with SSSE3 is 20% faster than without SSSE3, so
# given its near-ubiquity in the x86 installed base, it renders a distribution
@ -52,9 +48,10 @@ if defined(disableMarchNative):
switch("passL", "-march=haswell -mtune=generic")
else:
if defined(marchOptimized):
# https://github.com/status-im/nimbus-eth2/blob/stable/docs/cpu_features.md#bmi2--adx
switch("passC", "-march=broadwell -mtune=generic")
switch("passL", "-march=broadwell -mtune=generic")
# -march=broadwell: https://github.com/status-im/nimbus-eth2/blob/stable/docs/cpu_features.md#bmi2--adx
# Changed to x86-64-v2 for broader support
switch("passC", "-march=x86-64-v2 -mtune=generic")
switch("passL", "-march=x86-64-v2 -mtune=generic")
else:
switch("passC", "-mssse3")
switch("passL", "-mssse3")
@ -76,6 +73,7 @@ else:
on
--opt:
speed
--excessiveStackTrace:
on
# enable metric collection
@ -85,8 +83,6 @@ else:
--define:
nimTypeNames
switch("define", "withoutPCRE")
# the default open files limit is too low on macOS (512), breaking the
# "--debugger:native" build. It can be increased with `ulimit -n 1024`.
if not defined(macosx) and not defined(android):

View File

@ -70,17 +70,17 @@ proc buildLibrary(name: string, srcDir = "./", params = "", `type` = "static") =
extra_params &= " " & paramStr(i)
if `type` == "static":
exec "nim c" & " --out:build/" & name &
".a --threads:on --app:staticlib --opt:size --noMain --mm:refc --header -d:metrics --nimMainPrefix:libwaku --skipParentCfg:on -d:discv5_protocol_id=d5waku " &
".a --threads:on --app:staticlib --opt:speed --noMain --mm:refc --header -d:metrics --nimMainPrefix:libwaku --skipParentCfg:on -d:discv5_protocol_id=d5waku " &
extra_params & " " & srcDir & name & ".nim"
else:
let lib_name = (when defined(windows): toDll(name) else: name & ".so")
when defined(windows):
exec "nim c" & " --out:build/" & lib_name &
" --threads:on --app:lib --opt:size --noMain --mm:refc --header -d:metrics --nimMainPrefix:libwaku --skipParentCfg:off -d:discv5_protocol_id=d5waku " &
" --threads:on --app:lib --opt:speed --noMain --mm:refc --header -d:metrics --nimMainPrefix:libwaku --skipParentCfg:off -d:discv5_protocol_id=d5waku " &
extra_params & " " & srcDir & name & ".nim"
else:
exec "nim c" & " --out:build/" & lib_name &
" --threads:on --app:lib --opt:size --noMain --mm:refc --header -d:metrics --nimMainPrefix:libwaku --skipParentCfg:on -d:discv5_protocol_id=d5waku " &
" --threads:on --app:lib --opt:speed --noMain --mm:refc --header -d:metrics --nimMainPrefix:libwaku --skipParentCfg:on -d:discv5_protocol_id=d5waku " &
extra_params & " " & srcDir & name & ".nim"
proc buildMobileAndroid(srcDir = ".", params = "") =