joeycastillo / Sensor-Watch

A board replacement for the classic Casio F-91W wristwatch
Other
1.02k stars 210 forks source link

Enable LTO #326

Open WesleyAC opened 7 months ago

WesleyAC commented 7 months ago

This saves around 4% of space on the default build, and likely reduces power consumption as well, although I'm not sure by how much. Numbers from TI 1 suggest that it might be a ~2-3% speed improvement (they measure 3.8% using -O3, but we're using -Os so we should expect slightly less), which would probably translate to at least a few days of extra battery life.

The change to the .vectors section is from a blog post 2 that did a excellent job explaining the exact problem I had.

WesleyAC commented 7 months ago

Putting the LTO flags in make.mk results in significantly more optimization (reducing space by 7.97% as opposed to 4.29%), but breaks the build for starter-project, which accidentally uses a bunch of stdlib stuff that doesn't actually exist, a latent bug that is triggered by trying to use LTO. The correct flags could likely fix this, things like -lnosys, -specs=nano.specs, and -specs=nosys.specs, but I couldn't manage to get this working, unfortunately. Will probably take another stab at it later.

matheusmoreira commented 4 months ago

LTO and whole program optimization is vital for reducing code size!

which accidentally uses a bunch of stdlib stuff that doesn't actually exist

Please elaborate, which missing symbols are referenced? I have some experience reducing libc footprint. Will try to build this when I have more time.