Repository navigation
Description
Tracked in #2974.
Smoking-gun pattern (from the meta)
Per the bloat report at .build/symbols/esp32s3-fbuild/report.md, every 1-4 KB fl::* symbol on ESP32-S3 Blink references _Unwind_Resume (156 B once + landing pad metadata per call site). The per-call-site cost is roughly 100-200 B of exception unwinding tables at each FL_WARN / FL_ERROR / FL_INFO site, because the compiler must assume that the temporary fl::sstream and the fl::string it carries can throw on destruction.
From #2974's analysis:
Per FL_WARN/FL_ERROR call site: ~200-300 B inline (sstream ctor + format << chain + log_emit call) ~100-200 B exception landing pad metadata (string/sstream dtors can throw)
Removing the landing pads is the cheapest, lowest-risk win because nothing in the destructor chain actually throws today — it's just that the compiler can't prove it.
Current state (observed)
Destructors are declared with the FL_NOEXCEPT macro, but FL_NOEXCEPT is currently a no-op on every platform:
src/fl/stl/noexcept.h:
// FL_NOEXCEPT: intentionally a noop on all platforms.
// noexcept was causing too many platform compatibility issues (AVR, WASM, etc.)
// so it is disabled everywhere until a robust cross-platform solution is found.
#ifndef FL_NOEXCEPT
#define FL_NOEXCEPT
#endifSo while the source intent is clearly "these dtors don't throw", the compiler sees no noexcept specifier and dutifully emits landing pads at every call site. This is precisely the bloat the meta is targeting.
Destructor chain inventory
| Type | Location | Has explicit dtor? | Currently marked? | Effective state |
|---|---|---|---|---|
fl::basic_string |
src/fl/stl/basic_string.h:439 |
yes (~basic_string() FL_NOEXCEPT;) |
FL_NOEXCEPT (no-op) |
potentially throwing |
fl::sstream |
src/fl/stl/strstream.h:34 |
no — implicit | n/a | inherits from string mStr -> potentially throwing |
fl::StringHolder |
src/fl/stl/detail/string_holder.h:18 |
yes | FL_NOEXCEPT (no-op) |
potentially throwing |
fl::variant<...> |
src/fl/stl/variant.h:52 |
yes (~variant() FL_NOEXCEPT { reset(); }) |
FL_NOEXCEPT (no-op) |
potentially throwing |
fl::shared_ptr<StringHolder> |
src/fl/stl/shared_ptr.h |
yes | FL_NOEXCEPT (no-op) |
potentially throwing |
fl::detail::ControlBlockBase (virtual) |
src/fl/stl/shared_ptr.h:39 |
yes (virtual ~ControlBlockBase() FL_NOEXCEPT;) |
FL_NOEXCEPT (no-op) |
potentially throwing |
~basic_string() body in src/fl/stl/basic_string.cpp.hpp:19 is {} — all real cleanup happens via implicit member destruction of mStorage (the variant), which calls into shared_ptr -> StringHolder destruction. Implicit dtor noexcept-ness is derived from member subobjects, so the entire chain must be noexcept for the spec to actually propagate to the call site.
Proposed fix
The minimum change is to make FL_NOEXCEPT expand to the real noexcept keyword for the platforms where C++11 is fully supported (essentially every modern target — desktop, ESP32, Teensy, WASM). Per the comment in noexcept.h the historical block was "AVR, WASM, etc." — both AVR-GCC and Emscripten have supported noexcept for years, so the macro can almost certainly be turned on globally.
Option A (preferred — single source change, fixes the whole chain at once):
// src/fl/stl/noexcept.h
#ifndef FL_NOEXCEPT
#define FL_NOEXCEPT noexcept
#define FL_HAS_NOEXCEPT 1
#endifOption B (conservative — opt-in per dtor): keep FL_NOEXCEPT as a no-op but introduce a separate FL_DTOR_NOEXCEPT macro that always expands to noexcept, and apply it only to the dtors in the chain above. This avoids touching every existing call site but does require auditing each dtor in the chain individually.
Either way the chain that must end up noexcept for the optimization to land is:
fl::basic_string::~basic_string()fl::sstream::~sstream()(implicit — fixing the basic_string chain fixes this for free)fl::StringHolder::~StringHolder()fl::variant<NotNullStringHolderPtr, ConstLiteral, ConstView>::~variant()(and itsreset()helper)fl::shared_ptr<StringHolder>::~shared_ptr()fl::detail::ControlBlockBase::~ControlBlockBase()(virtual — must benoexceptin the base for any override to benoexcept)fl::detail::ControlBlock<StringHolder>::destroy_object()/destroy_control_block()
Chain elements that may need work first
StringHolderallocates withnew[]ingrow(). Ifnewthrows (i.e., notnothrow new), thenStringHolderconstructors aren'tnoexcept— but constructors aren't relevant here; the dtor just callsdelete[] mData, which is implicitlynoexcept. Fine.variant::reset()calls placed destructors. As long as every contained type's dtor isnoexcept,variant::~variant()isnoexcept. The variant inbasic_stringholdsNotNullStringHolderPtr(shared_ptr),ConstLiteral(trivial),ConstView(trivial) — only the shared_ptr matters, and its dtor isdeleteon a control block, which is implicitlynoexcept.ControlBlockBase::~ControlBlockBase()is virtual. Its definition lives out-of-line insrc/fl/stl/shared_ptr.cpp.hpp(anchored there for vtable ODR reasons). The override-able-while-noexcept rule means both the base declaration and every override must have the same exception spec; flipping the macro covers both.- Nothing in the chain actually throws today — the only potential throw points would be
new, and the onlynewin the chain is in theadd_shared_ref/ refcount paths which use atomic counters, not allocations. The dtors themselves only dodeleteand arithmetic.
Estimated savings
Per the meta's analysis: ~100-200 B per FL_WARN / FL_ERROR call site in landing pad metadata. The meta identifies 8 distinct 1-4 KB functions, each containing 3-5 log sites, plus the broader 30+ call sites in the 1-4 KB band. Conservative estimate:
- ~3-6 KB recovered on ESP32-S3 Blink from landing-pad elimination alone
- Plus the shared
_Unwind_Resume(156 B) reference may itself drop out if no FastLED code path remains that requires it (depends on other dtors in the binary)
This is the lowest-risk single change in the #2974 plan: no semantic changes, no code reorganization, just a macro flip and (if needed) a small audit of the destructor chain to confirm nothing actually throws.
Verification plan
- Toggle
FL_NOEXCEPT->noexcept(Option A). bash compile esp32s3 --examples Blink— confirm clean build.bash bloat esp32s3— diff.build/symbols/esp32s3-fbuild/report.mdfor_Unwind_Resumereferences and total flash delta on the 8 target functions.bash test --cpp— confirm no regression in unit tests (the noexcept change should be transparent unless some test relies on dtor-throwing-during-stack-unwind, which would already be a bug).- Spot-check AVR (
uno) and WASM compile to confirmnoexceptis accepted on the historically-problematic targets.
Refs
- Meta: Reduce per-symbol bloat in the FastLED 1-4KB function band on ESP32-S3 (logging must stay enabled) #2974
- Bloat report:
.build/symbols/esp32s3-fbuild/report.md - Graphviz sidecars:
.build/symbols/esp32s3-fbuild/graphs/ - Files:
src/fl/stl/noexcept.h(the macro)src/fl/stl/basic_string.h+src/fl/stl/basic_string.cpp.hppsrc/fl/stl/strstream.h+src/fl/stl/strstream.cpp.hppsrc/fl/stl/detail/string_holder.hsrc/fl/stl/variant.hsrc/fl/stl/shared_ptr.h+src/fl/stl/shared_ptr.cpp.hpp
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity