Skip to content

Reduce binary size by removing unused functions even when not using LTO (~200-900kb reduction) - #2068

Open
dsnopek wants to merge 1 commit into
godotengine:masterfrom
dsnopek:binary-size-unused-code
Open

dsnopek wants to merge 1 commit into
godotengine:masterfrom
dsnopek:binary-size-unused-code

Conversation

@dsnopek

@dsnopek dsnopek commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

It appears that without LTO, we were only passing the flags for the compiler to remove unused compilation units, not unused functions.

This PR attempts to add those flags for both GCC and Clang (I tried a bunch of stuff with MSVC, but wasn't able to find anything that reduced size at all):

Platform / Compiler Size Before Size After Change
Linux / GCC 13 2,866 KB 1,945 KB -921 KB (-32.1%)
Linux / Clang 18 3,063 KB 2,443 KB -620 KB (-20.2%)
Windows / MinGW GCC 13 2,100 KB 2,089 KB -11 KB (-0.5%)
Android / NDK 28.1 1,161 KB 466 KB -695 KB (-59.9%)
macOS / Clang 21 (w/ debug_symbols=yes) 1,045 KB 831 KB -214 KB (-20.5%)

Re Windows: It seems MingGW can't fully do this optimization without LTO, which is why (a) the change is so small and (b) it doesn't add the -ffunction-sections -fdata-sections flags because that actually makes the size bigger, not smaller

Re macOS: We were already using -Wl,-dead_strip with debug_symbols=no, so this only adds it in the debug_symbols=yes case

With these changes, the effect of using either LTO or build_profile is much smaller, which is nice, because LTO is slow and using build_profile requires extra work

@dsnopek dsnopek added this to the 10.x milestone Oct 8, 2026
@dsnopek
dsnopek requested a review from a team October 8, 2026 12:35
@dsnopek
dsnopek requested a review from a team as a code owner October 8, 2026 12:35
@dsnopek dsnopek added enhancement This is an enhancement on the current functionality cmake topic:buildsystem Related to the buildsystem or CI setup labels Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmake enhancement This is an enhancement on the current functionality topic:buildsystem Related to the buildsystem or CI setup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants