From 2dac0866f1aeff0f40182d40eb35f41bfc2b099b Mon Sep 17 00:00:00 2001 From: Fabiana Cecin Date: Thu, 2 Apr 2026 07:10:02 -0300 Subject: [PATCH] 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 --- Makefile | 2 +- config.nims | 14 +++++--------- waku.nimble | 6 +++--- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 37341792c..809c191fd 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/config.nims b/config.nims index f74fe183f..0655bf092 100644 --- a/config.nims +++ b/config.nims @@ -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): diff --git a/waku.nimble b/waku.nimble index c63d20246..a8959b6a3 100644 --- a/waku.nimble +++ b/waku.nimble @@ -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 = "") =