Repository navigation
Description
Tracked in #2974 (item TBD-I).
Function under audit
fl::ChannelEngineRMTImpl::processPendingChannels() — 1,078 B on ESP32-S3 Blink.
Located at src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp:981.
Called by:
beginTransmission(×15)poll(×6)
The function is already marked FL_NOEXCEPT, but the body still pays full exception-cleanup metadata because the callees inside the dispatch loop are mostly noexcept but writeWithPadding and the inline FL_WARN/FL_LOG_RMT machinery are not.
Top callees (per bloat report)
| Callee | Bytes |
|---|---|
fl::ChannelEngineRMTImpl::acquireChannel(...) |
516 B |
fl::RMTBufferPool::acquireDMA(unsigned int) |
394 B |
fl::ChannelEngineRMTImpl::releaseChannel(...) |
374 B |
fl::RMTBufferPool::releaseInternal(fl::span<unsigned char>) |
362 B |
fl::detail::log_emit |
222 B |
fl::RMTBufferPool::releaseDMA() |
178 B |
_Unwind_Resume |
156 B |
fl::ChannelData::writeWithPadding(fl::span<unsigned char>) |
100 B |
plus fl::sstream::appendFormatted × 2, fl::string::string, fl::basic_string::~, etc. |
Loop structure (verified in source)
processPendingChannels() is a for(size_t i=0; i<mPendingChannels.size(); ) walk over the pending queue. Each iteration tries to start one transmission and contains four distinct try-acquire / on-fail-log / on-success-continue branches, plus a final swap-and-pop on full success:
- Acquire HW channel —
acquireChannel(...); on fail:++i; continue;(no log) - Verify encoder —
if (!channel->encoder); on fail:FL_WARN(...)+releaseChannel(channel)+++i; continue; - Acquire pooled buffer —
mBufferPool.acquireDMA(...)oracquireInternal(...); on empty:FL_WARN(...)+releaseChannel(channel)+++i; continue; writeWithPaddinginto the pooled buffer (no error path, but callee is not noexcept)- Enable channel —
mPeripheral.enableChannel(...); on fail:FL_LOG_RMT(...)+ buffer release (DMA or internal) +releaseChannel(channel)+++i; continue; - Reset encoder —
mPeripheral.resetEncoder(...); on fail:FL_LOG_RMT(...)+disableChannel(...)+ buffer release +releaseChannel(channel)+++i; continue; - Transmit —
mPeripheral.transmit(...); on fail:FL_WARN(...)+disableChannel(...)+ buffer release +releaseChannel(channel)+++i; continue; - Success log —
FL_LOG_RMT(\"Started transmission for pin ...\")+ swap-and-pop
That's 6 distinct failure branches (steps 2, 3, 5, 6, 7) carrying full log-call-site bursts and inline cleanup blocks, plus the success log site — 7 sstream/log call sites total in a single function body, each with its own landing-pad metadata for the destructors of the temporary sstream / string that build the message.
Per-branch cost analysis
- Each FL_WARN / FL_LOG_RMT site: ~200-300 B inline (sstream ctor +
<<chain +log_emitcall) + ~100-200 B landing pad metadata for sstream/string destructors that the compiler currently treats as potentially throwing. - 7 log sites × ~150 B landing pad = ~1 KB of pure landing-pad overhead in a 1,078 B function — i.e. the majority of the function's size is exception-cleanup metadata, not actual work.
- Verified:
acquireChannel,releaseChannel, allRMTBufferPool::{acquire,release}{DMA,Internal}are already declaredFL_NOEXCEPT(seebuffer_pool.h:51,60,67,72andchannel_driver_rmt.cpp.hpp:390-394).processPendingChannelsitself is alsoFL_NOEXCEPT(line 981). - Remaining non-noexcept callees:
fl::ChannelData::writeWithPadding(fl::span<u8>)— declaredFL_NOEXCEPTindata.h:110but the definition indata.cpp.hpp:62is missing thenoexceptspecifier. Marking the definition to match the declaration eliminates the landing pad around the writeWithPadding call.FL_WARN/FL_LOG_RMTmachinery (fl::sstreamctor/dtor,fl::stringdtor,log_emit) — currently the dominant landing-pad source, addressed by TBD-A (mark sstream/string dtors noexcept).
Cross-references (these apply directly here)
- TBD-A — noexcept destructors on
fl::basic_string+fl::sstream. This single fix removes the per-log-site landing pad metadata for all 7 log sites in this function. Largest individual lever. - TBD-D — consolidate error paths via
expected<>::failure(...). The 6 failure branches all follow the same pattern: cleanup + log +++i; continue;. They can be folded into per-step helper functions that returnexpected<void, FailureKind>; the loop body then has a singleFL_WARNsite at the bottom that switches on the failure kind. Same approach proposed forreconfigureForNetwork()/createChannel(...)in TBD-D. - Quick win: add
noexcept(orFL_NOEXCEPT) to the definition ofChannelData::writeWithPaddingindata.cpp.hpp:62to match the header declaration — strictly an oversight, costs nothing.
Estimated savings
~300-500 B — smaller than the bigger 2 KB+ functions in this meta because processPendingChannels is itself only ~1 KB, but the pattern (6 nearly-identical cleanup branches + 7 log sites) is the same one TBD-A and TBD-D target. Once those land cross-cuttingly, this function inherits most of the savings automatically.
Suggested follow-up order
- Fix
writeWithPaddingdefinitionnoexceptmismatch (trivial, no behavior change, removes one landing pad). - Land TBD-A (sstream/string dtors noexcept) — eliminates landing pads from all 7 log sites in this function.
- Apply TBD-D pattern: refactor the 6 failure branches into helpers returning
fl::expected<void, FailureKind>and consolidate the FL_WARN to one bottom-of-loop site keyed on the failure kind.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity