Page 1 of 1

ESP32S3 : Possible to optimise the compilation ??

Posted: Thu Feb 16, 2023 7:35 pm
by ThomasESP32
Good afternoon,

I am working on a ESP32S3 WROOM 1 module and after writing some part of my firmware,
I see that the code size after compilation is quite big (600Ko).

However, I did not write a lot of code and I have seen some bigger programs on other microcontroller
with a size smaller than the one of my firmware.

I am using Bluetooth with Bluedroid library, I have included the Helix MP3 library and have juste written
some tasks without a lot of instructions inside.

Do you know if there a options or something like that, which can be used in order to optimize the size of the code
after compilation ?

Do you have any ideas please ?

Best regards,

Thomas TRUILHE

Re: ESP32S3 : Possible to optimise the compilation ??

Posted: Thu Feb 16, 2023 8:11 pm
by MicroController
Yes, you can choose to compile optimized for speed (-O2), debugging (-Og), or size (-Os), selectable in menuconfig.

However, you probably don't have to worry about code size (yet): There is a huge overhead (a few 100's of kb) for OS, WiFi/Bluetooth binaries, driver code &c. Fortunately, this overhead occurs only once and is independent of your own code. So, when you see 600kb of flash used, it could be quasi-constant 400kb of "system" code and only 200kb of your application code; in other words, if you have 4Mb of flash, and system occupies 10% of that, then your actual application at the moment only consumed 200kb/(4096kb-10%) ~ 5% of what you can use. (Just some rough guestimations, but the point is that once the big chunk of system code is included in your binary the application will go on to grow relatively slowly as you add more of your application code.)

Re: ESP32S3 : Possible to optimise the compilation ??

Posted: Sun Mar 05, 2023 12:04 pm
by MicroController
I just found out about idf.py size-components which gives you a nice breakdown of static memory usage of the components included in your application :)
Your main application code is listed as "libmain.a"...