Repository navigation
Description
Why this issue exists
Split from the now-closed rundown meta #3122 row B2. Item 3.2 of meta #2856 ("fl::sstream operator<< → printf-style log backend") was sized as the single highest-ROI of #2856's five architectural items (~5-10 KB on ESP32-S3 Blink) but is genuinely too big for a "go" / "skip" rundown commitment — it touches every FL_WARN / FL_LOG_* / FL_DBG call site in the codebase and changes their compilation behavior. Pulling it into its own focused issue lets us plan the API contract and migration without forcing it through a one-sentence-to-unblock format.
Problem
fl::sstream is a header-only operator-chain logger. Every FL_WARN(...) call site instantiates a fresh chain of operator<< template specializations for whatever types it streams, and each specialization carries its own rodata strings (separators, formatters, prefix/suffix). On a typical ESP32-S3 Blink build the libFastLED.a carries 75 FL_WARN/FL_LOG sites in channel_driver_rmt.cpp.hpp, 59 in rmt_memory_manager.cpp.hpp — each contributing to the per-site weight that the #2886 audit measured (#2886 row #1: 58,770 B for the transitive closure of one ClocklessIdf5<> ctor).
printf (or snprintf) is the opposite pattern: a single shared TU does the formatting, every call site is just a function call with a format string and varargs. Newlib's vfprintf cluster is ~36 KB but that already lives in the binary today (used by Serial.printf etc.), so the marginal cost of routing FastLED logs through it is zero or negative — we'd remove the per-site sstream rodata in exchange for shared printf calls.
Proposed architecture
Three sub-questions, each non-trivial:
1. API contract
Two options:
a. Keep FL_WARN(stream-expression) source-compatible, swap the backend.
#define FL_WARN(x) ::fl::detail::log_sstream_to_printf(x)Requires a sstream-shim that captures the operator<<-chain result into a temporary buffer, then routes through printf. Saves migration effort but doesn't actually shrink the binary — the operator<< chains still instantiate per-site, they just write to the shim instead of to Serial.
b. Migrate call sites to printf-style.
FL_WARN("RMT memory: %u bytes used / %u free", used, free);Real binary win because operator<< chains are gone. But ~400+ call sites need rewriting, and inline expressions like FL_WARN("foo " << myFunc()) need expansion to format strings.
Recommendation: (b), with a transition macro FL_WARN_LEGACY(x) that wraps the old form during migration so we can land it in passes.
2. Format-string safety
Switching to printf opens the door to format-string bugs. Two safeguards:
__attribute__((format(printf, N, M)))on theFL_WARNfunction so GCC/Clang verify format-string ↔ arg-type matches at compile time.- A custom-clang-tool check in
ci/lint_cpp_rs/that catchesFL_WARN(some_string_var, ...)(i.e. non-literal format strings — they bypass theprintfattribute).
3. Newlib NANO compatibility
Several boards (per tools/sdkconfig_for_smallest_fastled.defaults) enable CONFIG_NEWLIB_NANO_FORMAT=y which drops %f/%lld/%llu from printf. Our refactored call sites need to:
- Audit which existing FL_WARN sites stream
float/i64/u64and decide whether to keep them as nano-incompatible (gated by#if FASTLED_LOG_VERBOSITY > 0) or rewrite to use integer-only formatting. - Add a
FL_WARN_NANO_INCOMPAT(...)variant that errors at compile time when NANO is on, so we catch regressions.
Scope of the actual implementation PR
Once the API and safeguards are agreed:
- Introduce
FL_PRINTF_FORMATmacro infl/system/log.h(or wherever the FL_WARN/FL_LOG entry points live) —__attribute__((format(printf,N,M)))on GCC/Clang, empty on MSVC. - Add the printf-style
FL_WARN_F/FL_LOG_F/FL_DBG_Fmacros alongside the existing sstream ones. Both work side-by-side initially. - Add the non-literal-format clang-tool check in
ci/lint_cpp_rs/src/lint_core/. - Migrate the hot-path call sites (the top-25 weighted ones from Meta: ESP32-S3 Blink bloat reduction (file:line concrete plan) — supersedes #2885 #2886) to the new macros — typically batches of 5-10 sites per PR.
- Add a NANO-compat audit test that walks all migrated call sites and verifies format-string compatibility.
- Deprecate the original
FL_WARN(stream-expr)form once migration is complete — gate it behind#define FL_ALLOW_LEGACY_SSTREAM_LOGso users who depend on the old form opt in explicitly.
Acceptance
- ESP32-S3 NEOPIXEL Blink binary shrinks by ≥ 5,000 B vs the post-Meta: ESP32-S3 Blink bloat reduction (file:line concrete plan) — supersedes #2885 #2886-Stage-1 baseline (338,117 B → ≤ 333,117 B).
- No
FL_WARN/FL_LOGregression — every existing log message still reaches the serial console with at-least-equivalent semantic content. - Format-string attribute catches at least one bug at compile time during migration (proves the safeguard works).
- NANO-compat test catches at least one
%for%lldintroduced during migration (proves the audit works).
Why this is a focused issue rather than rundown-row work
The original rundown meta #3122 B2 mis-scoped this as a single rundown-row commitment. The actual work is API design + lint infrastructure + ~400 call-site migrations + NANO compatibility + format-string-attribute discipline — easily 2-3 weeks of focused work spread across many PRs. Pulling it into its own issue lets us plan it properly. See the closeout comment on #3122 for the full rundown context.
Cross-references
- Parent meta: Meta: ESP32-S3 binary-size reduction — Batch 3 (successor to #2773) #2856 (binary-size Batch 3). This issue is the focused track for item 3.2 of that meta.
- Bloat audit that motivates the savings target: Meta: ESP32-S3 Blink bloat reduction (file:line concrete plan) — supersedes #2885 #2886 (now mirroring
docs/SLIM_ESP32S3.md). - Closed rundown that spawned this: [meta] Actionable-work rundown — all off-bench items from the 2026-06-15/16 meta walk #3122.
- Related — sibling Stage 4 (cold-helper audit) and Stage 5 (
basic_string::writesimplification — shipped in perf(string): consolidate basic_string::write overloads (refs #3122 B5 / #2886 Stage 5) #3152) both touch the same FL_WARN closure but at smaller scale.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Jun 19, 2026
Status audit (2026-06-19)
A walk through the acceptance criteria against the current
master:FL_WARN_F/FL_LOG_F/FL_DBG_Falongside sstream macrossrc/fl/log/log.hsince #3190git log --oneline -- src/platforms/esp/32/drivers/rmt/rmt_5/shows commitda59e86e2 Migrate logging macros to printf style (#3190); the two cited hot files (channel_driver_rmt.cpp.hpp,rmt_memory_manager.cpp.hpp) contain zero remainingFL_WARN(... << ...)stream-form calls — onlyFL_WARN_F(\"%s\", ...)/FL_LOG_RMT_F(...)FL_WARN(stream-expr)form / unify under one entry pointFL_WARN(...)macro accepts both forms via argument-count dispatch;_Fmacros become aliasesFL_PRINTF_FORMATmacro (__attribute__((format(printf, N, M))))fl::printfitself infl/stl/stdio.hci/lint_cpp_rs/infrastructure; not blocking%f/%lld.github/workflows/check_esp32_size.yml) is what enforces the 5 KB win on each pushRemaining stream-form sites
Grep
FL_WARN\s*\([^)]*<<acrosssrc/reports ~79 hits across 22 files. These break down into two buckets:Cannot reasonably be migrated (template code or header-only generic formatting — printf can't bind arbitrary types via templates):
src/fl/task/promise.h,src/fl/task/promise_result.h,src/fl/task/executor.hsrc/fl/stl/shared_ptr.h,src/fl/stl/json.h,src/fl/stl/json/types.hsrc/fl/audio/fft/fft_impl.hsrc/fl/gfx/raster_sparse.hsrc/fl/channels/spi.h,src/fl/channels/spi/multi_lane_device.hsrc/fl/math/transposition.hsrc/fl/net/http/fetch.hThese genuinely need
operator<<because the payload type is not known at the call site (template parameter / arbitrary user type). They are also off the ESP32-S3 NEOPIXEL Blink hot path.Cold non-hot-path sites that COULD be migrated, but won't move the binary-size needle:
src/platforms/wasm/ui.cpp.hpp(6),src/platforms/wasm/timer.cpp.hpp(3) — WASM-only, doesn't ship on embeddedsrc/platforms/shared/ui/json/ui_manager.cpp.hpp(12),ui.cpp.hpp(13),audio.cpp.hpp(1) — JSON UI manipulationsrc/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp(3 — all commented out)Recommendation
Close this issue once #3273 (which provides the unified FL_WARN(...) entry point that drops the _F suffix from new code) merges. The binary-size acceptance criterion is best tracked by the existing CI size workflow; the lint-infrastructure and NANO-audit items belong in their own focused issues (or #3174 where they already partially overlap).
refactor(log): unify FL_WARN/FL_WARN_F via argument-count dispatch (#…
zackees commentedon Jun 19, 2026
Closing as substantially complete via merged PRs:
channel_driver_rmt.cpp.hppandrmt_memory_manager.cpp.hpp(the two largest contributors per Meta: ESP32-S3 Blink bloat reduction (file:line concrete plan) — supersedes #2885 #2886 audit). Zero stream-formFL_WARN(...<<...)calls remain in either file today.FL_WARN(...)/FL_ERROR(...)/FL_INFO(...)/FL_PRINT(...)entry point that accepts both stream- and printf-style via macro-level argument-count dispatch._Fmacros are now thin aliases — new code drops the_Fsuffix.Remaining ~79 stream-form sites in
src/are either template code that genuinely needsoperator<<(e.g.fl/task/promise.h,fl/stl/json/types.h,fl/stl/shared_ptr.h) or off-the-hot-path WASM/UI/HTTP files. The binary-size acceptance criterion is best tracked by the existing.github/workflows/check_esp32_size.ymlsize workflow, which #3190 was specifically designed to satisfy.Deferred items (lint infrastructure, NANO-compat audit,
FL_PRINTF_FORMATlint tool) belong in their own focused follow-ups; they overlap with #3174's formatter-safety work rather than this issue's API/migration scope.feat(format): add generic {} placeholder to fl::printf/snprintf (#3174)…