Page 1 of 1

How to compile for release mode with -Os -O3

Posted: Wed Feb 05, 2020 9:06 pm
by willhelm
I have not been able to find out how to compile for release mode. When I copy an example and compile the example with make VERBOSE=1 I see that the compiler flags are -Og -ggdb, but I want the flags to be -Os -O3.

I tried "cmake -DCMAKE_BUILD_TYPE=Release" but that added a ton of files and broke the example.

Re: How to compile for release mode with -Os -O3

Posted: Wed Feb 05, 2020 10:31 pm
by ESP_Angus
Hi willhelm,

If you open the project configuration menu, there's an item to set the compiler optimization level. We don't currently support the "normal" CMake way of setting debug/release. Recent ESP-IDF versions support -Og, -Os and -O2 as separate levels.

Setting "-Os -O3" is the same as setting "-O3". To quote the gcc man page: "If you use multiple -O options, with or without level numbers, the last such option is the one that is effective."

ESP-IDF doesn't currently support -O3, recommend using -O2 if you want the best performance and don't mind some binary size increase or -Os if you want minimal binary size. On our architecture -O3 can also grow the binary size significantly compared to -O2, leading to lower real-world performance on ESP32s because of the flash cache without major benefits. For this reason we haven't prioritised supporting this level.

Angus

Re: How to compile for release mode with -Os -O3

Posted: Thu Feb 06, 2020 12:46 am
by willhelm
Thank you :mrgreen: