Repository navigation
docs(esp32): add CONFIG_NEWLIB_NANO_FORMAT=y to Stage 3 sdkconfig overlay (~20-30 KB) - #2916
Conversation
…rlay Closes #2915. Adds the biggest missing single lever to the Stage 3 overlay file shipped in #2896. The standard newlib printf cluster — `_vfprintf_r` (11.3 KB), `_svfprintf_r` (11.1 KB), `_svfiprintf_r` (7.3 KB), `_vfiprintf_r` (7.3 KB), `_dtoa_r` (3.2 KB), `get_arg$isra$0` copies (4.9 KB cumulative) — collectively eats **~45 KB** on the post-#2911 ESP32-S3 NEOPIXEL Blink baseline (the largest non-FastLED cluster in the audit). Nano newlib drops it by 50-70%. ## Why this was missed The Stage 3 overlay #2896 targeted four sub-1.5 KB symbol clusters (coredump, IDF diag log, bootloader chatter, panic formatter) but left the dominant ~45 KB libc printf cluster unattended. Adding `CONFIG_NEWLIB_NANO_FORMAT=y` is a one-line config flip that's a larger lever than every other Stage 3 knob combined. ## The constraint Nano newlib printf has no `%f` / `%lf` / `%lld` / positional-arg support. Sketches that print floating-point values via printf will see literal format specifiers in the output instead of the formatted number. For LED installations this is rarely an issue — strip control code doesn't typically log floats. For sketches that DO need extended formats, the user either drops the overlay entirely or layers their own sdkconfig with `CONFIG_NEWLIB_NANO_FORMAT=n` after FastLED's. ## Files - `tools/sdkconfig_for_smallest_fastled.defaults` — new entry with inline constraint documentation, placed in the "Conservative knobs" section (it qualifies because most LED installations don't print floats). - `docs/SLIM_ESP32S3.md` — row 2 of the priority table updated from `~10-15 KB` → `~30-45 KB`. Stage 3 detail section's knob table expanded from 4 → 5 rows with the nano-newlib entry at the top, plus a new constraint sidebar. - `agents/docs/binary-size-analysis.md` — agent-facing copy of the priority table mirrors the SLIM doc update. ## Verification - `bash lint --cpp` → all C++ linting checks pass (this PR doesn't touch C++). - The overlay file remains opt-in (users must wire it into `board_build.sdkconfig_defaults` themselves). Default behavior is unchanged for users who haven't already chosen the overlay. - Measured savings will be validated on a follow-up build with the overlay applied. Expected: ~20-30 KB drop in `total_flash` vs current baseline (`347,004 B`). ## Expected savings - Pre-overlay (Stage 1 only): 347,004 B (current measured baseline). - Post-overlay (Stages 1+3 with nano printf): ≈ 347,004 - 25,000 = ~322,000 B (projected). - Gap to #2886 end-goal (280,000 B): ~42 KB remaining, most of which lives in #2856 (structural meta). The Stage 6 regression gate baseline does NOT change in this PR (the default-flag build is unchanged). A follow-up PR records the measured number after a build with the overlay applied. Refs #2886, #2915, #2896, #2906.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR extends the Stage 3 flash-saving overlay by adding ChangesNano printf configuration and documentation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Poem
✨ Finishing Touches🧪 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 |
…dies on FASTLED_LOG_RUNTIME_ENABLED (#2918) Closes #2917. Wraps the bodies of the two `FL_NO_INLINE` cold-path emit helpers in `fl::ChannelEngineRMTImpl` with `#if FASTLED_LOG_RUNTIME_ENABLED`. In release builds (NDEBUG → `FASTLED_LOG_VERBOSITY=0` per Stage 1) the helpers collapse to ~5 B function bodies (parameters cast to `(void)`, single `ret`), down from ~410-418 B each. ## Why the existing FL_NO_INLINE + FL_WARN pattern wasn't enough ```cpp FL_NO_INLINE void emitRecoveryWarning(...) FL_NOEXCEPT { fl::sstream msg; // [1] constructed unconditionally msg << "..." << ... << external_words; // [2] 15 operator<< calls fire FL_WARN(msg.str()); // [3] expands to no-op in release } ``` In release builds: - `FL_WARN(X)` expands to `do { if (false) { ... << X; } } while(0)` — optimizer DCEs the inner block (`msg.str()` call elided). - But `fl::sstream msg;` at [1] and `msg << ...` at [2] are **outside** the `if (false)` block. They have observable side effects on `msg`'s internal buffer (heap allocation, sequential writes), so the optimizer keeps the constructor + all 15 `operator<<` calls live in the function body. Result: the FL_NO_INLINE pulled the diagnostic chain out of the function it was hoisted from (`createChannel`) — into its own symbol — but the bytes stayed in the binary. ## Measured baseline (post-#2916 ELF, `master @ 5ca722e`) | Symbol | Size | |---|---:| | `fl::ChannelEngineRMTImpl::emitAllocationFailureError` (`$isra$0`) | 418 B | | `fl::ChannelEngineRMTImpl::emitRecoveryWarning` (`$isra$0`) | 410 B | | **Total in scope** | **~828 B** | Both symbols collapse to ~5 B after this PR. ## Behavior preserved - **Debug builds (`FASTLED_LOG_VERBOSITY=1`, default for non-NDEBUG):** the diagnostic emits exactly as before. Users debugging RMT allocation failures still see the multi-line action-required message. - **Release builds (`FASTLED_LOG_VERBOSITY=0`, NDEBUG default since #2890):** the helper bodies become empty; the callers in `attemptAllocationRecovery` still call them (the call overhead is ~5 B / site), but the bodies cost nothing. The FL_WARN macro itself was always a no-op in release; this PR makes the body that *built the message* match the macro's release-build behavior. ## Other emit helpers — audit notes - `attemptAllocationRecovery` (315 B total): contains its own FL_WARN and FL_LOG_RMT calls plus actual retry-loop arithmetic. The diagnostic calls go through the standard `FL_WARN` macro which is already `do { if (false) { ... } } while(0)` in release — the optimizer DCEs the inline chain. The 315 B is the retry-loop body + `Rmt5ChannelConfig retry_config(...)` construction; NOT the diagnostic emission. Leaving as-is. - `handleAllocateTxFailure` (63 B): already a `FL_NO_INLINE` cold helper at 63 B post-Stage-1 — almost entirely the fallback retry body. No further gating needed. ## Out of scope - Removing the FL_WARN calls from the source. They're useful in debug builds; the gate keeps them debug-build-active. - Auditing every FL_WARN call site in the RMT5 driver — the inline ones inside hot function bodies are already collapsed correctly by the `if (false)` DCE. ## Verification - `bash lint --cpp` → all C++ linting checks pass. - Behavior preserved by construction: the gate is on a build-time define that defaults to "diagnostics on" in debug builds. - Measured saving validated on this PR's CI run via the Stage 6 regression gate. Expected: `total_flash` drops by ~700-800 B from the current baseline of `347,004 B`. A follow-up commit ratchets the baseline file in the same PR. Refs #2886, #2917, #2908, #2911, #2914.
…) (#2937) Closes #2935 (partial — 4 configs failed silently during the measurement; the 6 successful configs flip the rows below). Ran `tests/measure_esp32s3_opt_ins.py --config all` end-to-end against `master @ f43f767`. The script's comparison table: | Config | SLIM row | total_flash | Δ vs baseline | |---|:---:|---:|---:| | baseline | 1 | 339,962 B | +0 B | | stage3 (sdkconfig overlay) | 2 | **280,738 B** | **−59,224 B** | | stage4 (FASTLED_RMT_STATIC_ALLOCATION) | 3 | 339,054 B | −908 B | | disable_ucs7604 | 7 | 336,158 B | **−3,804 B** | | disable_dyndriver | 8 | 339,025 B | −937 B | | disable_events | 9 | 331,928 B | **−8,034 B** | ## Headlines - **Stage 3 alone hits the #2886 end-goal.** The `tools/sdkconfig_for_smallest_fastled.defaults` overlay drops total_flash to 280,738 B — within 738 B of the 280,000 B target. Adding `CONFIG_NEWLIB_NANO_FORMAT=y` to the overlay in #2916 was the dominant lever (~30-45 KB of the saving). - **Three opt-in flags vastly exceeded projection** — `disable_events` delivered 4-8× projection (−8,034 B vs ~1-2 KB), `disable_ucs7604` delivered 6-9× (−3,804 B vs ~400-600 B). The dead-strip cascade pattern (see #2918 / #2925 / #2929 precedents) consistently delivers above projection when collapsing template-heavy machinery. ## What flipped 📊 → ✅ - Row 2 (overlay): −59,224 B measured. **Hits end-goal.** - Row 3 (FASTLED_RMT_STATIC_ALLOCATION): −908 B measured (well below projection — the static-allocation path is mostly already-optimal post-Stage-1). - Row 7 (FASTLED_DISABLE_UCS7604): −3,804 B measured. - Row 8 (FASTLED_DISABLE_DYNAMIC_DRIVER): −937 B measured. - Row 9 (FASTLED_DISABLE_CHANNEL_EVENTS): −8,034 B measured. ## What's still 📊 - Row 4 (FASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT): the config failed silently during the measurement run — see follow-up. - Row 5 (CONFIG_BT_ENABLED=n): no opt-in path in the current overlay (it's commented out per the user-side opt-in design). - Row 6 (FASTLED_DISABLE_SPI_CHIPSETS): also failed silently. The 4 missing configs (`stage2`, `stack`, `disable_spi`, `max_savings`) need a separate troubleshooting pass. The output redirection in the original measurement command discarded the per-build error messages so the failure cause isn't visible. A follow-up issue will rerun those with full output capture. ## Files - docs/SLIM_ESP32S3.md: - Baseline table updated with the new measured default-flag number (339,962 B) and a callout that Stage 3 alone hits the end-goal. - Rows 2 / 3 / 7 / 8 / 9 flip 📊 → ✅ with measured deltas inline. ## Verification - bash lint --cpp -> all C++ linting checks pass. - The measured numbers in the doc are word-for-word the script's table output. Refs #2886, #2935, #2906, #2934, #2916.
….py (#2939) * docs(esp32): flip SLIM rows 2/3/7/8/9 to ✅ with measured numbers (#2935) Closes #2935 (partial — 4 configs failed silently during the measurement; the 6 successful configs flip the rows below). Ran `tests/measure_esp32s3_opt_ins.py --config all` end-to-end against `master @ f43f767`. The script's comparison table: | Config | SLIM row | total_flash | Δ vs baseline | |---|:---:|---:|---:| | baseline | 1 | 339,962 B | +0 B | | stage3 (sdkconfig overlay) | 2 | **280,738 B** | **−59,224 B** | | stage4 (FASTLED_RMT_STATIC_ALLOCATION) | 3 | 339,054 B | −908 B | | disable_ucs7604 | 7 | 336,158 B | **−3,804 B** | | disable_dyndriver | 8 | 339,025 B | −937 B | | disable_events | 9 | 331,928 B | **−8,034 B** | ## Headlines - **Stage 3 alone hits the #2886 end-goal.** The `tools/sdkconfig_for_smallest_fastled.defaults` overlay drops total_flash to 280,738 B — within 738 B of the 280,000 B target. Adding `CONFIG_NEWLIB_NANO_FORMAT=y` to the overlay in #2916 was the dominant lever (~30-45 KB of the saving). - **Three opt-in flags vastly exceeded projection** — `disable_events` delivered 4-8× projection (−8,034 B vs ~1-2 KB), `disable_ucs7604` delivered 6-9× (−3,804 B vs ~400-600 B). The dead-strip cascade pattern (see #2918 / #2925 / #2929 precedents) consistently delivers above projection when collapsing template-heavy machinery. ## What flipped 📊 → ✅ - Row 2 (overlay): −59,224 B measured. **Hits end-goal.** - Row 3 (FASTLED_RMT_STATIC_ALLOCATION): −908 B measured (well below projection — the static-allocation path is mostly already-optimal post-Stage-1). - Row 7 (FASTLED_DISABLE_UCS7604): −3,804 B measured. - Row 8 (FASTLED_DISABLE_DYNAMIC_DRIVER): −937 B measured. - Row 9 (FASTLED_DISABLE_CHANNEL_EVENTS): −8,034 B measured. ## What's still 📊 - Row 4 (FASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT): the config failed silently during the measurement run — see follow-up. - Row 5 (CONFIG_BT_ENABLED=n): no opt-in path in the current overlay (it's commented out per the user-side opt-in design). - Row 6 (FASTLED_DISABLE_SPI_CHIPSETS): also failed silently. The 4 missing configs (`stage2`, `stack`, `disable_spi`, `max_savings`) need a separate troubleshooting pass. The output redirection in the original measurement command discarded the per-build error messages so the failure cause isn't visible. A follow-up issue will rerun those with full output capture. ## Files - docs/SLIM_ESP32S3.md: - Baseline table updated with the new measured default-flag number (339,962 B) and a callout that Stage 3 alone hits the end-goal. - Rows 2 / 3 / 7 / 8 / 9 flip 📊 → ✅ with measured deltas inline. ## Verification - bash lint --cpp -> all C++ linting checks pass. - The measured numbers in the doc are word-for-word the script's table output. Refs #2886, #2935, #2906, #2934, #2916. * feat(bloat): capture per-config build logs in measure_esp32s3_opt_ins.py Closes #2938 (partial — script side). Pre-#2938 the script ran `bash compile` / `bash bloat` for each config and discarded the per-build stdout/stderr. When a config crashed (see #2935 — 4 of 10 configs crashed on Windows with `extras+.cpp.o` exit 3221225794), the failure cause was invisible. Without that information, debugging required manual single-config reruns. This PR routes every config's compile and bloat output through a new `_run_with_log()` helper that writes to `.build/measure-logs/ <config>-{compile,bloat}.log` while tee'ing the same stream to the operator's terminal. On any future crash the log file is the diagnosable artifact. ## Files - tests/measure_esp32s3_opt_ins.py: - New `_LOG_DIR` constant (`.build/measure-logs`). - New `_run_with_log(cmd, log_name)` helper that does combined stdout+stderr capture via subprocess.Popen + chunked read. - `run_compile` and `run_bloat` take a `config_name` parameter and delegate to `_run_with_log`. - `measure_one` passes `cfg.name` to both. ## Verification - bash lint -> all linters pass (ruff, ty, C++, JS setup). - Smoke test (`--config baseline`) produces a log file pair at `.build/measure-logs/baseline-compile.log` and `.build/measure-logs/baseline-bloat.log`. ## Known follow-up The smoke test surfaced a separate issue: when consecutive runs use the same build_flags + sdkconfig, PIO returns a cached ELF from a prior run (potentially with different config). This is a build-cache hygiene problem orthogonal to the log capture. To be addressed in a future PR — possibly via `bash compile --clean` between configs or an explicit invalidation of `.build/pio/esp32s3/.pio/build/`. Refs #2886, #2938, #2935, #2906.
docs(esp32): add CONFIG_NEWLIB_NANO_FORMAT=y to Stage 3 sdkconfig overlay
Closes #2915.
Adds the biggest missing single lever to the Stage 3 overlay file
shipped in #2896. The standard newlib printf cluster —
_vfprintf_r(11.3 KB),
_svfprintf_r(11.1 KB),_svfiprintf_r(7.3 KB),_vfiprintf_r(7.3 KB),_dtoa_r(3.2 KB),get_arg$isra$0copies(4.9 KB cumulative) — collectively eats ~45 KB on the post-#2911
ESP32-S3 NEOPIXEL Blink baseline (the largest non-FastLED cluster in
the audit). Nano newlib drops it by 50-70%.
Why this was missed
The Stage 3 overlay #2896 targeted four sub-1.5 KB symbol clusters
(coredump, IDF diag log, bootloader chatter, panic formatter) but
left the dominant ~45 KB libc printf cluster unattended. Adding
CONFIG_NEWLIB_NANO_FORMAT=yis a one-line config flip that's alarger lever than every other Stage 3 knob combined.
The constraint
Nano newlib printf has no
%f/%lf/%lld/ positional-argsupport. Sketches that print floating-point values via printf will
see literal format specifiers in the output instead of the formatted
number. For LED installations this is rarely an issue — strip
control code doesn't typically log floats. For sketches that DO need
extended formats, the user either drops the overlay entirely or
layers their own sdkconfig with
CONFIG_NEWLIB_NANO_FORMAT=nafterFastLED's.
Files
tools/sdkconfig_for_smallest_fastled.defaults— new entry withinline constraint documentation, placed in the "Conservative knobs"
section (it qualifies because most LED installations don't print
floats).
docs/SLIM_ESP32S3.md— row 2 of the priority table updated from~10-15 KB→~30-45 KB. Stage 3 detail section's knob tableexpanded from 4 → 5 rows with the nano-newlib entry at the top,
plus a new constraint sidebar.
agents/docs/binary-size-analysis.md— agent-facing copy of thepriority table mirrors the SLIM doc update.
Verification
bash lint --cpp→ all C++ linting checks pass (this PR doesn'ttouch C++).
board_build.sdkconfig_defaultsthemselves). Default behavior isunchanged for users who haven't already chosen the overlay.
overlay applied. Expected: ~20-30 KB drop in
total_flashvscurrent baseline (
347,004 B).Expected savings
≈ 347,004 - 25,000 = ~322,000 B (projected).
most of which lives in Meta: ESP32-S3 binary-size reduction — Batch 3 (successor to #2773) #2856 (structural meta).
The Stage 6 regression gate baseline does NOT change in this PR
(the default-flag build is unchanged). A follow-up PR records the
measured number after a build with the overlay applied.
Refs #2886, #2915, #2896, #2906.
Summary by CodeRabbit