Skip to content

docs(esp32): add CONFIG_NEWLIB_NANO_FORMAT=y to Stage 3 sdkconfig overlay (~20-30 KB) - #2916

Merged
zackees merged 1 commit into
masterfrom
feat/2915-newlib-nano-overlay
Jun 7, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/2915-newlib-nano-overlay

Conversation

@zackees

@zackees zackees commented Jun 7, 2026 •

Copy link
Copy Markdown
Member

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$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

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

  • Documentation
    • Updated flash optimization documentation with improved memory savings estimates (up to 30-45 KB).
    • Added guidance for an optional configuration overlay that further reduces flash usage through a lightweight printf implementation.
    • Documented limitations of this optimization for floating-point and positional formatting, with override instructions for users who need these features.

…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.
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 7, 2026
@zackees
zackees merged commit 5ca722e into master Jun 7, 2026
1 check passed
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7837fe5c-2d37-46c0-8668-e67500b1f5ba

📥 Commits

Reviewing files that changed from the base of the PR and between 74bc797 and b8ef049.

📒 Files selected for processing (3)
  • agents/docs/binary-size-analysis.md
  • docs/SLIM_ESP32S3.md
  • tools/sdkconfig_for_smallest_fastled.defaults

📝 Walkthrough

Walkthrough

This PR extends the Stage 3 flash-saving overlay by adding CONFIG_NEWLIB_NANO_FORMAT=y to switch newlib to nano printf/scanf implementations, reducing the libc printf symbol cluster by ~20–30 KB. Configuration and documentation are updated across all guidance surfaces: the overlay itself, the ESP32-S3 SLIM guide, and the agent-facing binary-size analysis copy.

Changes

Nano printf configuration and documentation

Layer / File(s) Summary
Nano newlib format configuration
tools/sdkconfig_for_smallest_fastled.defaults
Adds CONFIG_NEWLIB_NANO_FORMAT=y to the Conservative knobs section with inline documentation of the ~20–30 KB projected saving from collapsing the libc printf cluster (_vfprintf_r, _svfprintf_r, _svfiprintf_r, _vfiprintf_r, _dtoa_r, get_arg) and explicit constraint notes: no %f, %lf, %lld, or positional format specifier support in the nano variant.
User and agent documentation for nano printf lever
docs/SLIM_ESP32S3.md, agents/docs/binary-size-analysis.md
Updated the "Release-build flash savers" table rows to cite the new nano printf knob and revise total Stage 3 savings from ~10–15 KB to ~30–45 KB. Added a dedicated constraint subsection in the per-stage detail for Stage 3 that explains nano printf formatting limitations and how to override the setting if sketches print floating-point values. Mirrored the savings update to the agent-facing binary-size-analysis table for consistency.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • #2915 — parent issue: defines the nano printf lever, projected savings, constraints, and acceptance criteria that this PR fulfills.
  • #2886 — meta issue: Stage 3 bloat-reduction plan; this PR extends Stage 3 by adding the largest unattended savings lever (libc printf cluster).
  • #2896 — introduced the Stage 3 overlay file; this PR adds the nano printf knob to that overlay.
  • #2906 — multi-config measurement driver; verification of the ~20–30 KB saving happens in a follow-up via measure_esp32s3_opt_ins.py --config stage3.

Possibly related PRs

  • FastLED/FastLED#2898: Introduced the docs/SLIM_ESP32S3.md structure and "Release-build flash savers" table that this PR updates.
  • FastLED/FastLED#2896: Shipped the original tools/sdkconfig_for_smallest_fastled.defaults overlay; this PR extends it with the nano printf knob.
  • FastLED/FastLED#2884: Introduced the agents/docs/binary-size-analysis.md binary-size table that this PR updates.

Poem

🐰 The nano printf hops in with glee,
Shrinking symbols by tens of three,
No floats allowed, but who's to care?
Twenty KB vanished into air! 🎉

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/2915-newlib-nano-overlay

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 7, 2026
zackees added a commit that referenced this pull request Jun 7, 2026
…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.
zackees added a commit that referenced this pull request Jun 7, 2026
…) (#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.
zackees added a commit that referenced this pull request Jun 7, 2026
….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.
@zackees
zackees deleted the feat/2915-newlib-nano-overlay branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Stage 3 extension: add CONFIG_NEWLIB_NANO_FORMAT=y (~20-30 KB) (#2886)

1 participant