gysmo38 / mitsubishi2MQTT

Mitsubishi to MQTT with ESP8266 module
GNU Lesser General Public License v2.1
393 stars 141 forks source link

Move large strings to flash to conserve ram #35

Closed chrdavis closed 4 years ago

chrdavis commented 4 years ago

This change moves large string constants to flash memory instead of ram to ensure the device has enough resources. Also includes general readability cleanup. This reduces RAM usage by 15k.

chrdavis commented 4 years ago

Here is a comparison of the before and after numbers compiling for a WEMOS D1

Executable segment sizes:

BEFORE

IROM : 363476 - code in flash (default or ICACHE_FLASH_ATTR) IRAM : 28204 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs...) DATA : 1356 ) - initialized variables (global, static) in RAM/HEAP RODATA : 18784 ) / 81920 - constants (global, static) in RAM/HEAP BSS : 27320 ) - zeroed variables (global, static) in RAM/HEAP

Sketch uses 411820 bytes (39%) of program storage space. Maximum is 1044464 bytes. Global variables use 47460 bytes (57%) of dynamic memory, leaving 34460 bytes for local variables. Maximum is 81920 bytes.

AFTER

IROM : 378152 - code in flash (default or ICACHE_FLASH_ATTR) IRAM : 28204 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs...) DATA : 1368 ) - initialized variables (global, static) in RAM/HEAP RODATA : 3620 ) / 81920 - constants (global, static) in RAM/HEAP BSS : 27048 ) - zeroed variables (global, static) in RAM/HEAP

Sketch uses 411344 bytes (39%) of program storage space. Maximum is 1044464 bytes. Global variables use 32036 bytes (39%) of dynamic memory, leaving 49884 bytes for local variables. Maximum is 81920 bytes.

Perf win of 15424 bytes of dynamic memory (33% reduction). This will make the program more reliable.

gysmo38 commented 4 years ago

Thank a lot for this improvement