Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ESP32 Huge jump in Program Size for minimal program #11274

Answered by me-no-dev
brownrb asked this question in Q&A
Discussion options

Board

ESP32 Dev Module

Device Description

No other board. Just ESP32 Dev Module,

Hardware Configuration

None

Version

latest stable Release (if not listed below)

IDE Name

Arduino IDE 2.3.5

Operating System

Windows 11

Flash frequency

80 Mhz

PSRAM enabled

no

Upload speed

115200

Description

I was trying to upgrade an existing ESP32 Program but even with all program options disabled the program size was 90%.

I decided to write a minimal program and report the program size for different ESP32 Core, from 2.0.13 to 3.2.0
Here are the results


Arduino IDE 2.3.5
ESP32 Dev Module
nullprog.ino as shown in next section

ESP32 Core 2.0.13
Sketch uses 257465 bytes (19%) of program storage space.
Global variables use 21432 bytes (6%) of dynamic memory

ESP32 Core 2.0.17
Sketch uses 258113 bytes (19%) of program storage space.
Global variables use 21432 bytes (6%) of dynamic memory

ESP32 Core 3.0.0
Sketch uses 889873 bytes (67%) of program storage space.
Global variables use 40724 bytes (12%) of dynamic memory,

ESP32 Core 3.1.3
Sketch uses 903108 bytes (68%) of program storage space.
Global variables use 44724 bytes (13%) of dynamic memory

ESP32 Core 3.2.0
Sketch uses 905882 bytes (69%) of program storage space.
Global variables use 46304 bytes (14%) of dynamic memory

My Question then is
Why the huge jump in program size from ESP32 Core 2.0.13 to Core 3.2.0
19% Program space to 69% program space,

I can no longer program the esp32 boards with the application (Weather station) because the program size is now (using Core 3.2.0) in excess of 100%.

Is there something I am missing here or perhaps not understanding the huge jump in program size from 2.x to 3.x of the ESP32 Core versions?

Any suggestions most welcome.

regards
Robert

Sketch

//nullprog.ino
#include <Arduino.h>
#include <WiFiServer.h>
#include <WiFiClient.h>
#include <ArduinoJson.h>
#include "SPIFFS.h"
#include <WiFi.h>
#include <Math.h>
#include <Wire.h>
void setup() {}
void loop() {}

Debug Message

None, comparing output program size for different Core versions

Other Steps to Reproduce

No, just run the nullprog.ino
test results speak for themselves

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
You must be logged in to vote

I dug deep into this and here is my conclusion:

  • Size increase comes from the WiFi library after the network layer refactoring in v3
  • It is present on empty sketch, because we always instantiate the WiFi object
  • This was true even before, but now we include proper destructors for the AP and STA interfaces
  • The destructors call WiFi.mode() internally, which in turn links to all low level WiFi and Netif init/deinit methods
  • Commenting out the calls to WiFi.mode() in the destructors, brings back the flash size to 300+KB

Now with that said:

  • There is no real scenario, where you will include the WiFi library, but never use it. If you will use only ETH/PPP, then include Network.h instead.
  • Any use ...

Replies: 9 comments 4 replies

Comment options

You can resize the partitions by allocating more space for app0 and app1 by reducing SPIFFS. For example app 1408 Spiffs 828:
`# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,

otadata, data, ota, 0xe000, 0x2000,

app0, app, ota_0, 0x10000, 0x160000,

app1, app, ota_1, 0x170000,0x160000,

spiffs, data, spiffs, 0x330000,0xD0000,`

I myself do not really understand why the idf kernel has grown so much in size. The second surprise for you will be the use of RAM. Personally, I will have to switch to esp32 with a larger memory size of 8-16 MB. But the fact that there is little RAM left threatens the use of esp32 at all. Something simple is still possible, but multifunctional devices with the current psram policy have already reached 60 KB and less free for me. Which no longer allows using https.

You must be logged in to vote
0 replies
Comment options

Thank you for your comment. I appreciate the response and your thoughts.

Yes, I know about partitions and heap size and all about that and SPIFFS etc. I have been using esp32 for a number of years now (as well as esp8266 before that). The partition scheme really does not help here, as the project also uses OTA updates. As the project is now stable and been in place for some time, partioning was explored and changed over time to where it is today. Been there, done that, took home the medal so to speak.

RAM is not an issue for me. But code space is. The problem is if all the project options are enabled, the resultant code space significantly exceeds 100%. With just 1 option enabled, a web server, program space is 90%.

To be honest, none of it addresses the concern I expressed, let alone explain why the increase.

I also feel that moving to a discussion could be interpreted as a "its not a real convern - live it - all your fault - write better code".

I come back to the fact the the explosion of program space used by core now renders my solutions totally worthless if moving to the latest core version. The project was often referred to as an esp32 killer app. Now its progably gonna be referred to the app that esp32 core killed. Just my thoughts. Not blaming anyone.

Regards
Robert

You must be logged in to vote
1 reply
Comment options

I partly understood that yes, this is our problem and we have to live with it.

I moved to version 3.x.x only because of Matter, I still keep my main version on the distant 1.0.2 just because of memory issues. Now I decided to switch to ESP32 with 8-16 MB of PSRAM, because in addition to the web server, web client, websocket server and client, I need to implement Matter support. I also wrote for the 8266, there was still plenty of space there, and strangely enough, RAM was enough. I haven’t written off the 8266 yet.

Good luck to you!!!

Comment options

I dug deep into this and here is my conclusion:

  • Size increase comes from the WiFi library after the network layer refactoring in v3
  • It is present on empty sketch, because we always instantiate the WiFi object
  • This was true even before, but now we include proper destructors for the AP and STA interfaces
  • The destructors call WiFi.mode() internally, which in turn links to all low level WiFi and Netif init/deinit methods
  • Commenting out the calls to WiFi.mode() in the destructors, brings back the flash size to 300+KB

Now with that said:

  • There is no real scenario, where you will include the WiFi library, but never use it. If you will use only ETH/PPP, then include Network.h instead.
  • Any use of the WiFi library will inevitably call WiFi.mode() which will link to all those things anyway and bring the size back to the same amount.

With all of the above, I conclude that this is not a real world issue. Yes, the WiFi stack has increased in size in ESP-IDF, but we have no control over that.

You must be logged in to vote
3 replies
Comment options

Thank you so much for your work!!! I suspected that the memory problem is in the IDF itself and does not depend on porting for Arduino.

If you have the opportunity, please consider more aggressive use of PSRAM in Arduino’s menuconfig settings. With the current default settings, PSRAM is used by the system in rare cases.

Comment options

me-no-dev
Appreciate the reply.
That being the case, the flow on effect is that the selected partition scheme (ESP32 Dev Module) is now rendered useless unless NOT using Wifi. Because there is no program space left to add anything of substance before the program space exceeds 100%.

I have observed the same issues with other available partiton schemes. The majority of those suffer from the same spave issues.

It is increasingly looking like the only real solution (apart from moving away from ESP32) is to use a custom partition definition.

Because this increase affects all the available partition spaces, perhaps it might be prudent to look at existing partition definitions and modify them to hold a larger size of program space, considering the IDF changes increased program space from 19% (old IDF) to 63% (new IDF)?

My concern (apart from the projects) is that new users moving to the ESP32 could encounter these same issues and be deterred from using ESP32 in their projects because program space can now be easily become a major issue for them (and apart from the frustration that also brings)

Regards
Robert

Comment options

There are plenty of partition options. For example "no-fs" gives you almost 2MB APP partition. If we are to modify current partitions, this will cause other issues, especially with partitions that have file systems. The result will be that FS will no longer mount, it will need to be re-formatted and data will be lost.

Answer selected by me-no-dev
Comment options

ThanksI expected as much. I can only say that prior - I had everything fitting within the space under prior's esp32 arduino core. OTA, SPIFFS, code, everything. Now I have nothing, as nothing fits anymore. My code is unaltered, The only different is the core code went from 19% to well over 64% an increase of about 300% I have all ready tried custom partitions. Its the core size space which prevents me from coming up with viable solutions. I tried to find esp32 dev module 8MB flash but could find none searching on various sites (ebay, aliexpress, google search etc). That would have been a viable solution, basically replacing the chip would have been an upgrade path. Please consider this closed. I appreciate your time and feedback. Yesterday I started to move to a different platform, as that now appears my only path. Current users can either stay with the older core etc, but cannot update. Once again, I thank you for all your feedback, and fully understand that this is outside the control of the team. RegardsRobert On Friday, May 2, 2025 at 11:08:12 PM GMT+12, Me No Dev ***@***.***> wrote: There are plenty of partition options. For example "no-fs" gives you almost 2MB APP partition. If we are to modify current partitions, this will cause other issues, especially with partitions that have file systems. The result will be that FS will no longer mount, it will need to be re-formatted and data will be lost. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: ***@***.***>
You must be logged in to vote
0 replies
Comment options

Facing a similar issue. The trouble is, there are a large number of devices that were orignally shipped in one configuration (1.2MB APP, 1.5MB spiffs, with OTA). When the base firmware size went overboard, it makes it harder to push updates. For newer ones, I have moved to bigger flash. Older ones out in the field poses some challenge because of this. Wonder if anyone else is on the same boat.

You must be logged in to vote
0 replies
Comment options

I have the same problem. I had to install a portable version of Arduino with an old core for old devices. In the code, I have to handle the differences and exclude what is not supported. This way, I can write one project and compile it in different versions of Arduino for both old and new devices.

#define oldVersionCode 1 #if oldVersionCode //code for old version #else ///code for new version #endif

You must be logged in to vote
0 replies
Comment options

@brownrb - Is this project open source? I'd like to build it using Arduino Core 3.2.0 and check what can be done to reduce the final binary size. Thanks!

You must be logged in to vote
0 replies
Comment options

that work on new core is underway and in testing. However I have moved away from ESP32-DEV module and new hardware boards (gerbers) will be available soon On Tuesday, June 3, 2025 at 03:58:49 AM GMT+12, Sugar Glider ***@***.***> wrote: @brownrb - Is this project open source? I'd like to build it using Arduino Core 3.2.0 and check what can be done to reduce the final binary size. Thanks! — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: ***@***.***>
You must be logged in to vote
0 replies
Comment options

basically that project is now end of life to those core increases. Removal of functions/code is not an option.So a new v2 project based on new hardware is taking place now. On Monday, June 2, 2025 at 08:52:28 AM GMT+12, ValdayMl ***@***.***> wrote: I have the same problem. I had to install a portable version of Arduino with an old core for old devices. In the code, I have to handle the differences and exclude what is not supported. This way, I can write one project and compile it in different versions of Arduino for both old and new devices. #define oldVersionCode 1 #if oldVersionCode //code for old version #else ///code for new version #endif — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: ***@***.***>
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #11269 on April 22, 2025 11:16.

AltStyle によって変換されたページ (->オリジナル) /