Code optimization

So, I am a bit confused here,
I am running a ESP32 project and I getting confusion information from the “Inspect” tool and the “run” tool. ( from terminal when I issue the command “platformIO run”.
First what they agree on:

  • RAM 320kByte
  • FLASH 4 Mbyte.

Then the confusing thing:
“Inspect” says 92% utilization of RAM and 36% of FLASH.
“Run” says 18,9% utilization of RAM and 115.1% of FLASH.

Another thing that is confusing for me.
“run” tells me that I have 1310720 bytes of FLASH. Should that not be 512 kBytes??

Probably there is something in those reports that I not understand, but please help me out her !!

When I noticed 115% utilization of FLASH i turned on all optimization flags I could find. They made absolutely no difference. Should they really not make any difference whatsoever ???

Why should it be be 512 kBytes? What board are you using, and what partition layout.

i.e. the default partition layout is for 1.2MB APP x 2 + 1.5MB SPIFFS … so 1310720 is right unless you’ve configured it differently…

More importantly… if you’re consuming 115.1% of flash… it sounds like you should be getting an error message, and be unable to upload your program to your ESP32… as I’d believe the ‘run’ output over the inspect output, as project inspection is a new feature, and has occasionally given some weird / incorrect results. One in particular I remember was where project inspection couldn’t tell that strings were being stored in FLASH, and no longer consuming RAM… :man_facepalming: Not sure if that has been resolved yet.

Why should it be be 512 kBytes?
4Mbit divided by 8, but I understand it is not so simple … but why can’t I use the hole FLASH memory?

Yes I get a error and it is not loading …
Any idea why the optimization flags don’t change anything??

Without you answering that question, I can’t answer

Because you haven’t told me how much memory your ESP32 board has… is it 4M (hence 512Kbyte) or is it 16M (hence 4Mbyte, and a more common size), and what partition layout you are using, which determines how much of your memory you can access at a time.

And without knowing how you “turned on all optimization flags I could find”, I don’t know why that didn’t make any difference. I take it you used the build-flags in your platformio.ini to pass parameters to the compiler/linker?

I am running a DevkitC with a Wrover-B development board. I understand now that it contains 4Mbyte Flash.
You earlier stated “1.2MB APP x 2 + 1.5MB SPIFFS” ( new to me, I belived that I had access to all 4MByte.

SPIFFS, is it where my application is loaded.

I have used “build_flags” in platformIO.ini

I have optimized my code and is down to a utilization of 90,2%

If I add add the -Os flag according to this document Optimize Options (Using the GNU Compiler Collection (GCC))
I had expected it to go down fro 90,2%

-Os already is the standard when compiling the firmware. Now I still have no idea why

is so different, maybe there’s a general issue with the Inspect tool. Can open an issue at Issues · platformio/platformio-core · GitHub or Issues · platformio/platform-espressif32 · GitHub with a preproducable project?

1 Like