8000
Skip to content

[shtcx] Combine log statements to reduce loop blocking - #12960

Merged
bdraco merged 1 commit into
devfrom
combine-logs-shtcx
Jan 5, 2026
Merged

[shtcx] Combine log statements to reduce loop blocking#12960
bdraco merged 1 commit into
devfrom
combine-logs-shtcx

Conversation

@bdraco
@bdraco bdraco commented Jan 5, 2026
Copy link
Copy Markdown
Member

What does this implement/fix?

Combine consecutive log statements into single calls using multi-line string literals.

Logging is one of the most intensive operations in ESPHome and blocks the event loop longer than most other operations. Each ESP_LOG* call involves formatting, memory allocation, serial output, and network packet transmission. Combining consecutive log statements reduces event loop blocking and the number of network packets sent to connected clients.

Note: The log processor reformats multi-line output so each line gets its own timestamp and log level prefix - the final output format is unchanged. Minor reordering of dump_config output may occur when LOG_PIN or other logging macros cannot be combined with ESP_LOG* calls - this is acceptable as it does not affect functionality.

See https://developers.esphome.io/architecture/logging/ for more details.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Developer breaking change (an API change that could break external components)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

Pull request in esphome-docs with documentation (if applicable):

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx
  • nRF52840

Example entry for config.yaml:

# N/A - no config changes

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

Copilot AI review requested due to automatic review settings January 5, 2026 02:12
@github-actions
github-actions Bot commented Jan 5, 2026
Copy link
Copy Markdown
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#12960
    components: [shtcx]
    refresh: 1h

(Added by the PR bot)

@codecov-commenter
codecov-commenter commented Jan 5, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.46%. Comparing base (1202756) to head (f40edb2).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev   #12960   +/-   ##
=======================================
  Coverage   73.46%   73.46%           
=======================================
  Files          53       53           
  Lines       11310    11310           
  Branches     1535     1535           
=======================================
  Hits         8309     8309           
  Misses       2602     2602           
  Partials      399      399           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR combines consecutive ESP_LOGCONFIG calls in the SHTCx component into a single multi-line log statement to reduce event loop blocking. Logging operations in ESPHome are resource-intensive, involving formatting, memory allocation, serial output, and network transmission. By combining consecutive log statements, this change reduces the number of individual logging operations and network packets sent to connected clients.

Key Changes

  • Combined two sequential log statements into one multi-line log call using string literals with embedded newline characters
  • Maintained the same output format through ESPHome's log processor which automatically reformats multi-line output

@github-actions
github-actions Bot commented Jan 5, 2026
Copy link
Copy Markdown
Contributor

Memory Impact Analysis

Components: shtcx
Platform: esp8266-ard

Metric Target Branch This PR Change
RAM 28,640 bytes 28,640 bytes ➡️ +0 bytes (0.00%)
Flash 281,939 bytes 281,923 bytes 📉 ✅ -16 bytes (-0.01%)
📊 Component Memory Breakdown
Component Target Flash PR Flash Change
[esphome]shtcx 1,013 bytes 1,002 bytes 📉 ✅ -11 bytes (-1.09%)
🔍 Symbol-Level Changes (click to expand)

Changed Symbols

Symbol Target Size PR Size Change
esphome::shtcx::SHTCXComponent::dump_config() 144 bytes 132 bytes 📉 -12 bytes (-8.33%)
std::_Function_handler<void (), esphome::shtcx::SHTCXComponent::update()::{lambda()#1}>::_M_invok...std::_Function_handler<void (), esphome::shtcx::SHTCXComponent::update()::{lambda()#1}>::_M_invoke(std::_Any_data const&)
251 bytes 252 bytes 📈 +1 bytes (+0.40%)

Note: This analysis measures static RAM and Flash usage only (compile-time allocation).
Dynamic memory (heap) cannot be measured automatically.
⚠️ You must test this PR on a real device to measure free heap and ensure no runtime memory issues.

This analysis runs automatically when components change. Memory usage is measured from a representative test configuration.

@bdraco
bdraco commented Jan 5, 2026
Copy link
Copy Markdown
Member Author

thanks

@bdraco
bdraco merged commit 4bc1a02 into dev Jan 5, 2026
42 checks passed
@bdraco
bdraco deleted the combine-logs-shtcx branch January 5, 2026 02:52
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

0