[logger] Use LogString for UART selection strings (saves 28 bytes RAM on ESP8266) - #10615
Merged
Conversation
Contributor
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#10615
components: [logger]
refresh: 1h(Added by the PR bot) |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes RAM usage on ESP8266 by moving the logger component's UART selection strings from RAM to PROGMEM (flash memory), saving 36 bytes of valuable RAM.
- Moves three UART selection strings ("UART0", "UART1", "UART0_SWAP") to PROGMEM
- Updates the string array and accessor function to read from flash memory
- Maintains identical functionality while reducing RAM footprint
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This reverts commit 9e56bc1.
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #10615 +/- ##
=======================================
Coverage 60.43% 60.43%
=======================================
Files 51 51
Lines 10482 10482
Branches 1400 1400
=======================================
Hits 6335 6335
Misses 3789 3789
Partials 358 358 β View full report in Codecov by Sentry. π New features to boost your workflow:
|
bdraco
marked this pull request as draft
September 5, 2025 15:37
bdraco
marked this pull request as ready for review
September 5, 2025 15:45
bdraco
marked this pull request as draft
September 5, 2025 16:09
bdraco
marked this pull request as ready for review
September 5, 2025 18:33
bdraco
marked this pull request as draft
September 5, 2025 18:33
bdraco
marked this pull request as ready for review
September 5, 2025 18:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this implement/fix?
This PR optimizes RAM usage on ESP8266 by converting the logger component's UART selection strings to use ESPHome's
LogStringpattern, which automatically stores strings in PROGMEM (flash memory) on ESP8266.The logger component uses strings to identify UART selections ("UART0", "UART1", "UART0_SWAP"). These strings were previously stored in RAM, consuming valuable memory on the ESP8266 platform which only has 80KB of RAM total. By using ESPHome's standard
LOG_STR()macro pattern, these strings are automatically placed in PROGMEM on ESP8266, freeing up RAM for application use.Types of changes
Related issue or feature (if applicable): N/A
Pull request in esphome-docs with documentation (if applicable): N/A
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed:
Summary
Converts logger UART selection strings to use ESPHome's
LogStringpattern for automatic PROGMEM storage on ESP8266, saving 28 bytes of RAM.Key Changes
get_uart_selection_()to returnconst LogString*instead ofconst char*LOG_STR()macroLOG_STR_ARG()for proper string extractionMemory Impact
ESP8266:
ESP32:
The trade-off of 8 bytes of flash for 28 bytes of RAM is excellent on ESP8266 where RAM is precious.
Benefits
LogString*return typeTesting
Verified on ESP8266 and ESP32: