WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Shrink the size  (Read 1226 times)

Offline polikuo

  • Hero Member
  • *****
  • Posts: 714
Shrink the size
« on: August 21, 2023, 07:42:39 AM »
I'm trying to build firefox which requires several other extensions.
One of them is cbindgen, which has its unique way for compilation.
If you check the notes, you'll see that none of them use any compile flags.

A bit of googling leads me to the stackoverflow.
In brief, he says by adding these lines into the .toml config, you get smaller binary and strip it in a go.
Code: [Select]
[profile.release]
opt-level = "z"
codegen-units = 1
panic = 'abort'
strip = true

[profile.release-lto]
inherits = "release"
lto = true
Note that, to optimize for size, "s" (opt-level = "s") is a synonym to "z".

A quick test on my pies (all with LTO)
Code: [Select]
$ du *
5.5M    cbindgen-pi4-default
1.7M    cbindgen-pi4-adjusted-stripped
3.8M    cbindgen-pi4-default-stripped
1.7M    cbindgen-pi3-adjusted-stripped

The hack isn't RPI specific, we can introduce it into other arch.
What do you think ?  :)

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 933
Re: Shrink the size
« Reply #1 on: August 21, 2023, 08:24:09 AM »
Hi polikuo!

-Oz was introduced in gcc12.

from https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Optimize-Options.html:

-Oz

    Optimize aggressively for size rather than speed. This may increase the number of instructions executed if those instructions require fewer bytes to encode. -Oz behaves similarly to -Os including enabling most -O2 optimizations.

Looks like -Ofast antipode.

Offline CardealRusso

  • Full Member
  • ***
  • Posts: 160
Re: Shrink the size
« Reply #2 on: August 21, 2023, 10:58:09 AM »
maybe tcc?