Repository navigation
feat(rmt5): FASTLED_RMT_STATIC_ALLOCATION opt-in macro (#2773 item 2.5 Level A) - #2846
Conversation
|
Complex PR? Review this PR in Change Stack to move by importance, not file order. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds opt-in macro ChangesRMT5 Static Allocation Mode
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/platforms/esp/32/drivers/rmt/rmt_5/common.h (1)
180-203: ⚡ Quick winClarify that constraints are contractual, not compile-time enforced.
The documentation states the user "is asserting at compile time" the constraints, but the implementation doesn't add compile-time checks (e.g.,
static_assert,#errorif network macros are detected). The macro changes runtime behavior under the assumption constraints are met; violations result in undefined behavior rather than compile errors.Consider rephrasing lines 193-196 to make this clearer:
-// Opt in (1): the planner collapses to a constant. calculateMemoryBlocks -// returns FASTLED_RMT_MEM_BLOCKS unconditionally; allocateTx skips the -// fallback retry + diagnostic block; freeDMA is a no-op. The user is -// asserting at compile time: +// Opt in (1): the planner collapses to a constant. calculateMemoryBlocks +// returns FASTLED_RMT_MEM_BLOCKS unconditionally, allowing the compiler +// to optimize away adaptive logic. The user must ensure the following +// constraints are met (violations lead to undefined behavior):This avoids implying compile-time enforcement while still documenting the contract.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/platforms/esp/32/drivers/rmt/rmt_5/common.h` around lines 180 - 203, The comments claiming the user "is asserting at compile time" are misleading because FASTLED_RMT_STATIC_ALLOCATION does not enforce those constraints; update the comment text around the FASTLED_RMT_STATIC_ALLOCATION block so it states that enabling it is a contractual/assumption the user must satisfy (not enforced by static_assert or preprocessor checks) and that violations lead to undefined/runtime behavior; mention the relevant behaviors affected (calculateMemoryBlocks, allocateTx fallback/diagnostics, freeDMA no-op) and recommend adding compile-time checks if enforcement is desired.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/platforms/esp/32/drivers/rmt/rmt_5/common.h`:
- Around line 180-203: The comments claiming the user "is asserting at compile
time" are misleading because FASTLED_RMT_STATIC_ALLOCATION does not enforce
those constraints; update the comment text around the
FASTLED_RMT_STATIC_ALLOCATION block so it states that enabling it is a
contractual/assumption the user must satisfy (not enforced by static_assert or
preprocessor checks) and that violations lead to undefined/runtime behavior;
mention the relevant behaviors affected (calculateMemoryBlocks, allocateTx
fallback/diagnostics, freeDMA no-op) and recommend adding compile-time checks if
enforcement is desired.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b224ad70-8524-42b7-b4e9-5378d2e3989c
📒 Files selected for processing (2)
src/platforms/esp/32/drivers/rmt/rmt_5/common.hsrc/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.cpp.hpp
…5 Level A)
When users opt in via:
#define FASTLED_RMT_STATIC_ALLOCATION 1
#include <FastLED.h>
calculateMemoryBlocks() collapses to a single `return FASTLED_RMT_MEM_BLOCKS`
unconditional constant — no memory-pressure detection, no network-aware
buffering, no single-buffer fallback retry, no diagnostic FL_LOG_RMT chains.
The runtime allocateTx path that depends on this then trivially constant-
folds through the linker.
The opt-in asserts at compile time that the sketch has:
- Exactly one addLeds<>() call, made before setup() returns
- No removeLeds() / late addLeds()
- No WiFi/Ethernet/Bluetooth during LED transmission
Default behavior (FASTLED_RMT_STATIC_ALLOCATION=0) is unchanged — the
adaptive planner stays live for all sketches that didn't opt in.
This is "Level A" of the design RFC posted on #2773. Level B (full
template-trait refactor with linker-driven specialization selection) is
deferred; Level A captures ~70% of item 2.5's headroom at minimal risk.
Estimated savings under FASTLED_RMT_STATIC_ALLOCATION=1:
~2-3 KB code on top of FASTLED_LOG_VERBOSITY=0 (#2791).
24c741c to
f7b6c71
Compare
…compile-time enforced (CR feedback on #2846)
FastLED#2856 item 3.6) Under FASTLED_RMT_STATIC_ALLOCATION=1 (FastLED#2846) the user has asserted no removeLeds() / late addLeds(). The destructor of ChannelEngineRMTImpl still calls memMgr.free() / memMgr.freeDMA() on every channel at process end, but the ledger isn't meaningfully tracked under static mode so the work is dead — yet it still pulls fl::vector_inlined::erase, the begin/end iterator chain, and the multi-line FL_LOG_RMT / FL_WARN operator<< instantiations into the binary. Skip both bodies under the macro. Default behavior (FASTLED_RMT_STATIC_ALLOCATION=0) is unchanged. Refs FastLED#2856 item 3.6. Stacks on FastLED#2846 (FASTLED_RMT_STATIC_ALLOCATION opt-in macro). Estimated savings: ~few hundred bytes additional when both FastLED#2791 (FASTLED_LOG_VERBOSITY=0) and FastLED#2846 are also opted in.
…#2856 item 3.5) The existing allocateTx / allocateRx return result<size_t, RmtMemoryError> — a sum type with discriminator + payload. At the 4 internal callers inside the RMT5 driver chain (ChannelEngineRMT::createChannel × 2, RmtRxChannelImpl::ctor + begin) the specific error code is never read; callers just log + return false on any failure. Add tryAllocateTx / tryAllocateRx wrappers returning bool + size_t out parameter. The result<>-bearing API is retained for callers that need error fidelity (tests, future callers, the public surface). Migrate the 4 internal sites to the new API. Mock RmtMemoryManager (rmt5_support_stubs.h) gets matching always-succeeds stubs so the host test build still links. Refs FastLED#2856 item 3.5. Estimated savings: small (call-site result<> constructor + .ok() + .value() decoded into bool check + out param read). Real win compounds with FastLED#2791 (FASTLED_LOG_VERBOSITY=0) and FastLED#2846 (FASTLED_RMT_STATIC_ALLOCATION=1) where the FL_WARN diagnostic chains already disappear.
This is the consolidated PR for items 3.1, 3.2, 3.3, 3.5 of FastLED#2856. Item 3.6 already merged via FastLED#2861; item 3.4 was already in master before FastLED#2856 was filed (encoder is already a runtime virtual on IRMT5Peripheral::createEncoder). Item 3.1 — Cold-helper split of ChannelEngineRMTImpl::~dtor ============================================================ The destructor body (drain-wait + per-channel cleanup loop + FL_WARN timeout diagnostic + FL_LOG_RMT trailer) is a cold path — only reached at process end. Move it into an FL_NO_INLINE destructorCleanup() helper so its operator<< instantiations + the multi-line cleanup loop body don't contribute to icache footprint in the steady-state code that calls into the engine. Item 3.2 — FL_WARN_LIT / FL_LOG_LIT for literal-only sites ========================================================== Each FL_WARN(literal) bakes an fl::sstream + operator<< chain for the file/line prefix + the literal at every call site. For sites that pass nothing but a literal string, that's pure overhead vs a single fl::println call. Add FL_WARN_LIT(literal) / FL_LOG_LIT(literal) macros: route literal- only messages through fl::println directly, dropping the file/line prefix. The literal carries its own "[RMT]" prefix to partially compensate. The non-literal FL_WARN remains available for sites that need operator<< formatting or the file/line prefix. Migrates the destructor timeout warning as a first proof-of-concept. Other call sites can move to FL_WARN_LIT incrementally. Item 3.3 — Skip NetworkDetector under FASTLED_RMT_STATIC_ALLOCATION =================================================================== ChannelEngineRMT::createChannel calls NetworkDetector::isAnyNetworkActive() on every allocation to choose network-mode vs idle-mode buffer sizing. Under FASTLED_RMT_STATIC_ALLOCATION the user has asserted no network during LED transmission (per FastLED#2846), so this resolves to constexpr false. The linker then drops the NetworkDetector singleton + WiFi-state-reading chain from the binary. Item 3.5 — tryAllocateTx / tryAllocateRx status-code variants ============================================================= (Same as the closed FastLED#2862 — cherry-picked here for the single combined PR.) Adds bool-returning wrappers around the result<>-bearing allocateTx/allocateRx for the 4 internal callsites that don't need the specific error code. Result<>-bearing API retained for tests + public callers. Refs FastLED#2856. Closes the actionable scope of the meta; the deferred items (full Level B refactor, full printf backend, full static-bind addLeds<>) are independently large enough to deserve their own issues and aren't safe to land in one PR session.
…2886 Stage 2) (#2894) Closes #2893. Adds a build-flag-gated strong override of the Arduino-ESP32 core's `shouldPrintChipDebugReport()` weak symbol. Setting build_flags = -DFASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT=1 in `platformio.ini` (or the equivalent in Arduino IDE `compiler.cpp.extra_flags`) makes the optimizer fold both `if (shouldPrintChipDebugReport())` branches at vendor `main.cpp:55` and `main.cpp:63` to dead code. `--gc-sections` then drops `printBeforeSetupInfo()` (~1,464 B at top-25 row #21 of #2886) plus its ~1-2 KB of formatted-stream rodata carrier strings — projected ~3 KB of flash savings on the ESP32-S3 NEOPIXEL Blink baseline. ## Why a build flag, not an include? The earlier design (an opt-in include `#include <extras/suppress_arduino_chip_debug_report.cpp.hpp>` in the user sketch) collided with the unity-build linter: every `.cpp.hpp` under `src/` is required to participate in a `_build.cpp.hpp` aggregator, which in turn is compiled by a `+.cpp` wrapper in `src/fl/build/`. The shim file is therefore unavoidably part of the library compilation unit. Gating the body on `FASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT` and `FL_IS_ESP32` keeps the default behavior unchanged for every user who doesn't explicitly opt in. Opt-in via build flag is the same ergonomic shape as `FASTLED_RMT_STATIC_ALLOCATION` (#2846) and `FASTLED_LOG_VERBOSITY` (#2791) — recognizable to existing users following the bloat-reduction docs. ## Files - `src/extras/suppress_arduino_chip_debug_report.cpp.hpp` — the shim. Empty body unless `FL_IS_ESP32 && FASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT`. - `src/extras/_build.cpp.hpp` — unity-build aggregator for `extras/`, documented as the home for build-flag-gated shims. - `src/fl/build/extras+.cpp` — independently-compiled wrapper TU that pulls `extras/_build.cpp.hpp` into the library build (matches the existing `platforms+.cpp` / `third_party+.cpp` pattern). - `ci/lint_cpp/test_unity_build.py` — register `fl/build/extras+.cpp` in `EXPECTED_BUILD_FILES` so the unity-build linter accepts the new wrapper. ## Verification - `bash lint --cpp` → all C++ linting checks pass; the pre-existing PlatformIO-internal-usage warnings (issue #2701) are warn-only and unchanged by this PR. - Flash savings (`bash bloat esp32s3 --build` with `-DFASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT=1`) measured by the Stage 6 verification gate; this PR only ships the mechanism. ## User-facing behavior | Build flag | ESP32 target | Effect | |---|---|---| | unset / `=0` | yes | no change (vendor weak default fires) | | `=1` | yes | strong override → `printBeforeSetupInfo()` dead-stripped | | any | no | shim expands to nothing | Refs #2886, #2893.
…rlay (#2886 Stage 3) (#2896) Closes #2895. Adds a documented, opt-in ESP-IDF sdkconfig overlay that users plug into `board_build.sdkconfig_defaults`. Drops ~10-15 KB of release-build flash on a typical ESP32 LED installation by disabling IDF components that a deployed strip never uses: | Knob | Eliminates | Savings | |---|---|---:| | `CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=n` | libespcoredump (top-25 rows #18 + #25, ~3 KB symbols + ~5 KB tail) | ~8 KB | | `CONFIG_LOG_DEFAULT_LEVEL=ESP_LOG_NONE` | libesp_diagnostics + IDF log strings (top-25 row #19) | ~3 KB | | `CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y` | bootloader-stage UART chatter | ~1 KB | | `CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y` | panic-time backtrace formatter | ~1-2 KB | `CONFIG_BT_ENABLED=n` is shipped commented-out (~15 KB extra when the project currently has BT on) — users uncomment when they know their sketch doesn't touch BLE/BT. ## Files - `tools/sdkconfig_for_smallest_fastled.defaults` — the overlay itself, with inline per-knob comments grounding each line in the #2886 top-25 attribution. - `agents/docs/binary-size-analysis.md` — adds a "Release-build flash savers (in order of impact)" table that lists this overlay alongside the FASTLED_LOG_VERBOSITY default (#2890), the boot-banner shim (#2894), and FASTLED_RMT_STATIC_ALLOCATION (#2846). Single reference point for what knobs exist and how to enable them. ## Why a user-side overlay, not a library-side default `sdkconfig` is consumed by the ESP-IDF build before any FastLED TU is compiled. FastLED cannot mutate IDF defaults from a library; the deliverable here is therefore a *shippable overlay file* the user points `board_build.sdkconfig_defaults` at, plus documentation that tells them which lines map to which savings. ## User integration ``` [env:esp32s3] board_build.sdkconfig_defaults = sdkconfig.defaults ${platformio.packages_dir}/framework-arduinoespressif32/tools/sdkconfig.defaults.esp32s3 ${PROJECT_LIBDEPS_DIR}/${PIOENV}/FastLED/tools/sdkconfig_for_smallest_fastled.defaults ``` (See the file's header for the full snippet; `PROJECT_LIBDEPS_DIR` resolution varies by PIO project layout.) ## Verification - `bash lint --cpp` → C++ linting passes (this PR is docs-only; pre-existing PlatformIO-internal-usage warnings unchanged). - Per-project flash deltas are user-side measurements; the projection table in `binary-size-analysis.md` cites the #2886 top-25 baseline attribution for each line. Refs #2886, #2895.
…tage 0) (#2898) Closes #2897. Adds a user-facing reference page that consolidates every release-build flash-saver FastLED currently ships into a single discoverable location. End users no longer have to grep across PRs and meta-issues to find the knobs. Sections: 1. **TL;DR** — a drop-in `platformio.ini` snippet that stacks Stages 1+2+3 and `FASTLED_RMT_STATIC_ALLOCATION` in one place. 2. **Baseline & how to measure** — pre-#2886 NEOPIXEL Blink baseline (388,380 B), Stage 6 target (≤ 280,000 B), `bash bloat esp32s3` pointer. 3. **Release-build flash savers (in priority order)** — five-row table with how-to-enable, savings, status (✅ measured vs. 📊 projected), and PR cross-link for each knob. 4. **Per-stage detail** — one section per shipped stage with the mechanism, file path, and integration snippet: - Stage 1 (`FASTLED_LOG_VERBOSITY=0`, now NDEBUG default) — #2890 - Stage 2 (`FASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT=1` build flag → strong override of vendor weak `shouldPrintChipDebugReport()`) — #2894 - Stage 3 (`tools/sdkconfig_for_smallest_fastled.defaults` overlay applied via `board_build.sdkconfig_defaults`) — #2896 - `FASTLED_RMT_STATIC_ALLOCATION=1` — #2846 (pre-existing) 5. **Situational notes** — Stage stacking, sdkconfig integration gotchas, `PROJECT_LIBDEPS_DIR` fallback. 6. **Measuring your build** — `bash bloat esp32s3` quickstart + diff pointer. 7. **Roadmap** — Stages 4 (cold-helper audit), 5 (basic_string::write simplification), 6 (CI regression gate). The ✅/📊 status flags on the priority table flip to ✅ when Stage 6 records measured deltas. Also adds a cross-reference from `agents/docs/binary-size-analysis.md` (the agent-facing reference shipped in #2896) to the new user-facing doc, with a maintenance note that future knobs must update both surfaces. ## Honesty about projections Every savings figure in this PR is marked 📊 (projected from the #2886 top-25 attribution). The ✅ status gets unlocked when Stage 6 of #2886 wires the regression-gate run that records measured baselines. The Roadmap section calls this out explicitly so readers know which numbers carry empirical weight. ## Verification - `bash lint --cpp` → all C++ linting checks pass; this PR adds no C++ code. - Doc references (`tools/sdkconfig_for_smallest_fastled.defaults`, `src/extras/suppress_arduino_chip_debug_report.cpp.hpp`, `src/fl/log/log.h:66-92`) verified against the post-#2896 tree. Refs #2886, #2897.
Summary
Adds `FASTLED_RMT_STATIC_ALLOCATION` opt-in macro. When set to 1 by the user, `RmtMemoryManager::calculateMemoryBlocks()` collapses to a single `return FASTLED_RMT_MEM_BLOCKS` constant — no memory-pressure detection, no network-aware buffering, no single-buffer fallback retry, no diagnostic FL_LOG_RMT chains. The runtime `allocateTx` path that depends on this then trivially constant-folds through the linker.
The opt-in asserts at compile time:
Default behavior (`FASTLED_RMT_STATIC_ALLOCATION=0`) is unchanged — the adaptive planner stays live for all sketches that didn't opt in.
Why "Level A"
This is the "Level A" path of the design RFC on the meta issue. Level B (full template-trait refactor with linker-driven specialization selection) was scoped at 3–5 days with medium risk; Level A is 1 day with low risk and captures ~70% of item 2.5's remaining headroom.
Estimated savings
`~2-3 KB` of `.text` on top of `FASTLED_LOG_VERBOSITY=0` (#2791), assuming the user opts in to both. Actual numbers will be measured against a clean ESP32-S3 Blink build once the local PIO toolchain is repaired (a previous disk cleanup wiped the package cache).
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit