Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4ee3892

Browse files
authored
Switches Android to ThinLTO and optimizes for space (#179)
ThinLTO is supposed to be faster during linking. The LTO optimization level is decreased to reduce inlining and hence binary size (Chrome uses the same LTO-O level on Android for the same reason). This reduces libflutter.so by 122,800 Bytes (120KB) uncompressed, which now comes in at 5,558,036 Bytes.
1 parent 9b79910 commit 4ee3892

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

build/config/compiler/BUILD.gn

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ if (is_win) {
810810
# Default "optimization on" config. On Windows, this favors size over speed.
811811
config("optimize") {
812812
lto_flags = []
813+
ld_lto_flags = []
813814
if (is_win) {
814815
# Favor size over speed, /O1 must be before the common flags. The GYP
815816
# build also specifies /Os and /GF but these are implied by /O1.
@@ -819,12 +820,13 @@ config("optimize") {
819820
} else if (is_android) {
820821
cflags = [ "-Oz" ] + common_optimize_on_cflags # Favor size over speed.
821822
if (enable_lto) {
822-
lto_flags += [ "-flto" ]
823+
lto_flags += [ "-flto=thin" ]
824+
ld_lto_flags += [ "-Wl,--lto-O0" ] # Favor size over speed.
823825
}
824826
} else {
825827
cflags = [ "-O2" ] + common_optimize_on_cflags
826828
}
827-
ldflags = common_optimize_on_ldflags + lto_flags
829+
ldflags = common_optimize_on_ldflags + lto_flags + ld_lto_flags
828830
cflags += lto_flags
829831
}
830832

0 commit comments

Comments
 (0)