Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put debug messages behind a define guard to reduce binary size #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AEManov20
Copy link

@AEManov20 AEManov20 commented Feb 1, 2024

I've put all Serial.print(s) behind a define guard (ENABLE_DEBUG_MESSAGES). When enabled, the debug messages take up 1448 bytes which is ~2% of the variables and constants section when compiling.

Here's the output when compiling with ENABLE_DEBUG_MESSAGES:

. Variables and constants in RAM (global, static), used 30936 / 80192 bytes (38%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ DATA     1500     initialized variables
╠══ RODATA   3044     constants       
╚══ BSS      26392    zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 60823 / 65536 bytes (92%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ ICACHE   32768    reserved space for flash instruction cache
╚══ IRAM     28055    code in IRAM    
. Code in flash (default, ICACHE_FLASH_ATTR), used 315464 / 1048576 bytes (30%)
║   SEGMENT  BYTES    DESCRIPTION
╚══ IROM     315464   code in flash   

Here's the output when compiling without ENABLE_DEBUG_MESSAGES:

. Variables and constants in RAM (global, static), used 29480 / 80192 bytes (36%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ DATA     1500     initialized variables
╠══ RODATA   1596     constants       
╚══ BSS      26384    zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 60823 / 65536 bytes (92%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ ICACHE   32768    reserved space for flash instruction cache
╚══ IRAM     28055    code in IRAM    
. Code in flash (default, ICACHE_FLASH_ATTR), used 314136 / 1048576 bytes (29%)
║   SEGMENT  BYTES    DESCRIPTION
╚══ IROM     314136   code in flash   

NOTE: These logs are valid when compiling for the ESP8266 platform. In other models the percentages may differ.
NOTE: These logs were generated when compiling the SimpleMQTTClient example.

@EdJoPaTo
Copy link
Contributor

Should this also remove the method to enable debug messages?
I would keep the internal variable for simplicity reasons but the public interface of it would be prone to mistakes then as it doesn't do anything.

I thought about it being duplicate in there, both runtime and compile time, but I don't really see a way to change that as both have their own use cases…

@AEManov20
Copy link
Author

AEManov20 commented Mar 3, 2024

The point of being able to disable it at compile time is to reduce the binary size of the firmware, leaving more space for code (or for when building for release/production).

Also about the runtime method for disabling debug messages, I forgot about it, that also can be placed behind a preprocessor guard, completely removing it from the interface when the #define flag for disabling debug messages is present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants