Conversation
|
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#12780
components: [modbus]
refresh: 1h(Added by the PR bot) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #12780 +/- ##
=======================================
Coverage 73.34% 73.34%
=======================================
Files 53 53
Lines 11284 11284
Branches 1531 1531
=======================================
Hits 8276 8276
Misses 2608 2608
Partials 400 400 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR optimizes verbose logging in the modbus component by replacing heap-allocated string formatting with stack-based buffers. The change eliminates std::string heap allocations in format_hex_pretty() calls by using the more efficient format_hex_pretty_to() function that writes directly to a stack buffer. The 192-byte buffers are conditionally compiled to avoid stack allocation when verbose logging is disabled.
- Introduces
MODBUS_MAX_LOG_BYTESconstant (64 bytes) to limit logged frame size - Replaces
format_hex_pretty(...).c_str()with stack-basedformat_hex_pretty_to()in bothsend()andsend_raw()functions - Adds compile guards to avoid stack allocation when verbose logging is disabled
Memory Impact AnalysisComponents:
📊 Component Memory Breakdown
🔍 Symbol-Level Changes (click to expand)Changed Symbols
This analysis runs automatically when components change. Memory usage is measured from a representative test configuration. |
What does this implement/fix?
Replace heap-allocating
format_hex_pretty(...).c_str()with stack-basedformat_hex_pretty_to()in the modbus component's verbose logging.This eliminates
std::stringheap allocations in the LOGV paths for bothsend()andsend_raw()functions. The buffers are wrapped in compile guards to avoid stack allocation when verbose logging is disabled.Buffer size is 192 bytes (
format_hex_pretty_size(64)) to cover typical Modbus frames while truncating unusually large ones.Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: