How to compile for release mode with -Os -O3

willhelm
Posts: 12
Joined: Sat Jul 13, 2019 4:41 pm

How to compile for release mode with -Os -O3

Postby willhelm » Wed Feb 05, 2020 9:06 pm

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.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

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

Postby ESP_Angus » Wed Feb 05, 2020 10:31 pm

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

willhelm
Posts: 12
Joined: Sat Jul 13, 2019 4:41 pm

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

Postby willhelm » Thu Feb 06, 2020 12:46 am

Thank you :mrgreen:

Who is online

Users browsing this forum: dzungpv, Google [Bot] and 98 guests