Repository navigation
tools(bloat): ship tests/measure_esp32s3_opt_ins.py multi-config audit driver - #2906
Conversation
…t driver Closes #2905. Ships a CLI driver that builds the ESP32-S3 NEOPIXEL Blink under each release-mode opt-in combo from #2886, runs `bash bloat esp32s3` against each ELF, and emits a Markdown comparison table sized to drop straight into the priority table in `docs/SLIM_ESP32S3.md`. The script is the bridge between the SLIM doc's projected (📊) entries and the measured (✅) ones. A follow-up doc PR runs the script, captures the table, and flips 📊 → ✅ for the rows backed by measurement. ## What ships | File | Role | |---|---| | `tests/measure_esp32s3_opt_ins.py` | Multi-config audit driver. CLI: `--config {baseline\|stage2\|stage3\|stage4\|stack\|all}`, `--example Blink`, `--out compare.md`, `--keep-platformio-ini-backup`. | | `agents/docs/binary-size-analysis.md` | One-line pointer to the script so future agents / users know how to refresh the doc's measurements. | ## Config matrix | Config | build_flags addition | sdkconfig overlay | Source SLIM row | |---|---|---|---| | `baseline` | (none) | (user default) | row 1 — Stage 1 (NDEBUG default) | | `stage2` | `-DFASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT=1` | (user default) | row 4 | | `stage3` | (none) | `+ tools/sdkconfig_for_smallest_fastled.defaults` | row 2 | | `stage4` | `-DFASTLED_RMT_STATIC_ALLOCATION=1` | (user default) | row 3 | | `stack` | Stages 2 + 3 + 4 all enabled | overlay applied | SLIM TL;DR snippet | ## Safety properties - **Backup / restore.** First action backs up `platformio.ini` → `platformio.ini.bak`. SIGINT / SIGTERM handlers restore the file before exit; `finally:` block restores on any other exit path. The backup is deleted on clean exit unless `--keep-platformio-ini-backup` is set. - **Targeted regex patch, not full INI re-parse.** PlatformIO's flavor of INI carries continuation lines and `${var.x}` interpolations that `configparser` mangles. The script only patches the `[env:esp32s3]` block via a regex that matches up to the next `[env:` header (or EOF) — well-defined in practice. - **Per-config report archival.** Each config's `report.json` gets copied to `report.<config>.json` in the same dir, so the per-symbol data is preserved for `.claude/symbolaudit/diff.py` comparisons. ## Verification - `bash lint` → all linters pass (Python via ruff + ty, C++, JS). The 6 pre-existing `ty` warnings about `os.system` are in unrelated CI scripts; not introduced by this PR. - The script's first-pass logic was reviewed against the actual `[env:esp32s3]` block in `platformio.ini` (extends `env:generic-esp`, carries `board_build.flash_size`, `board_build.partitions`, `build_flags`). The regex correctly identifies the block boundary. - Running the script end-to-end on a real machine produces the comparison table that the follow-up doc PR consumes; that run isn't in this PR because it's a separate measurement step (~16 min for 5 configs × ~3-4 min each). ## Out of scope - **The follow-up doc PR** that runs the script and flips 📊 → ✅ rows in `docs/SLIM_ESP32S3.md`. - **Ratcheting `tests/data/esp32s3_bloat_baseline.txt`** — the gate baseline only tightens when a measured saving lands in `src/`, not when a user-side build flag delivers the savings. - **CI integration** of the multi-config measurement. Initial scope is a developer-facing local tool. Refs #2886, #2905, #2904, #2900, #2898.
|
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 (2)
📝 WalkthroughWalkthroughThis PR introduces ChangesMeasurement Infrastructure
Sequence DiagramsequenceDiagram
participant CLI
participant platformio_ini as platformio.ini
participant build as bash compile
participant bloat as bash bloat
participant report as report.json
CLI->>platformio_ini: patch build_flags & overlay
CLI->>build: run compile
build->>report: generate
CLI->>bloat: run bloat esp32s3
bloat->>report: write total_flash
CLI->>report: read total_flash value
CLI->>report: archive as report.<config>.json
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
✨ 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 |
…Idf5 bloat (#2908) Closes #2907. Adds `fl::sort_small` — a public template that delegates directly to `fl::detail::insertion_sort` and skips the runtime fall-through inside `fl::detail::quicksort_impl`. Migrates three call sites in the `ClocklessIdf5` ctor transitive closure to use it. ## Why this is a real win `fl::sort` at `src/fl/stl/algorithm.h:564` dispatches to `detail::quicksort_impl`, which contains: ```cpp if (last - first <= 16) { insertion_sort(first, last, comp); return; } Iterator pivot = partition(first, last, comp); quicksort_impl(first, pivot, comp); quicksort_impl(pivot + 1, last, comp); ``` The bound is a runtime check, not `constexpr`. Per-template-parameter instantiation of `fl::sort` therefore emits the whole quicksort + partition + median-of-three + heap_sort body even when the call site provably operates on a bounded container ≤ 16 elements. The non-insertion-sort body is dead code for those call sites. `fl::sort_small` calls `detail::insertion_sort` directly, so the quicksort body is never instantiated for call sites that opt in. The new template guards an empty-or-single-element fast path to match the existing `fl::sort` precondition. ## Migrated call sites (all in ClocklessIdf5 transitive closure) | Site | Container | Bound | Why bounded | |---|---|---:|---| | `src/fl/channels/manager.cpp.hpp:137` | `mDrivers` | 4 | "Only 1-4 drivers expected" per existing comment | | `src/fl/channels/manager.cpp.hpp:251` | `mDrivers` | 4 | same — re-sort after priority change | | `src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp:362` | `fl::vector_inlined<ChannelDataPtr, 16>` | 16 | inline-capacity template parameter | All three are reachable from `BusTraits<Bus::RMT>::registerWithManager()` (called at `idf5_clockless.h:45`), which is the entry point that anchors the 48,694 B map-derived attribution to `ClocklessIdf5` in the 2026-06-06 measured audit (see #2886 audit comment). ## Out of scope (deferred follow-ups) Seven other `fl::sort` sites exist in `src/` that also operate on small bounded containers, but they're either outside the `ClocklessIdf5` transitive closure or in alternate drivers (parlio/uart). Migration is a one-line follow-up per site; deferred so the measured savings here are clearly attributable to the `ClocklessIdf5` closure. ## Expected savings Conservative estimate: 1-3 KB per template instantiation of the eliminated quicksort body. Across the three sites (each is a distinct `Compare` type → distinct instantiation), expected total reduction is 3-9 KB on the ESP32-S3 NEOPIXEL Blink build. The Stage 6 regression gate (`tests/test_esp32s3_bloat_regression.py`, baseline = `350568`) will validate the measurement on this PR's CI run. If the build comes in lower, a follow-up commit lowers the baseline file in the same PR. ## Verification - `bash lint --cpp` → all C++ linting checks pass. - Behavior preserved: `fl::sort_small` has the same semantic contract as `fl::sort` (same return = nothing, same compare-by-<, same in-place mutation, idempotent on already-sorted input). Only O() characteristics change: O(n²) worst case instead of O(n log n) — fine when n is bounded. - The 3 migrated sites all operate on ≤ 16-element containers per the table above. Refs #2886, #2907, #2904, #2906.
…rlay (#2916) 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.
…max_savings (#2934) Closes #2933. Adds coverage for the four opt-in build flags shipped after #2906: - `FASTLED_DISABLE_SPI_CHIPSETS=1` (#2914) — disable_spi config - `FASTLED_DISABLE_UCS7604=1` (#2921) — disable_ucs7604 config - `FASTLED_DISABLE_DYNAMIC_DRIVER=1` (#2927) — disable_dyndriver config - `FASTLED_DISABLE_CHANNEL_EVENTS=1` (#2932) — disable_events config Plus a new `max_savings` config that stacks ALL eight opt-ins (Stages 2 + 3 + 4 + the 4 new gates) — the headline cumulative saving for users who enable everything. Also adds a `slim_row` field to `OptInConfig` and a new `SLIM row` column to the comparison table. The output table now maps 1:1 onto the priority table in `docs/SLIM_ESP32S3.md`, making it copy-pasteable into a follow-up doc-flip PR. ## Files - `tests/measure_esp32s3_opt_ins.py`: - `OptInConfig` gains `slim_row: int | None`. - New module-level `_ALL_OPT_IN_FLAGS` tuple so the `max_savings` config doesn't drift from the per-flag configs. - 4 new configs + `max_savings` added to `CONFIGS`. - `format_table` gains the `SLIM row` column. ## Verification - `bash lint` -> all linters pass (ruff, ty, C++, JS setup). - No FastLED runtime change; doesn't affect any build. - The config matrix matches the SLIM doc priority table 1:1. ## Out of scope - Running the measurements. Separate follow-up PR. - Updating SLIM doc rows 📊 → ✅. Requires the measurements. Refs #2886, #2906, #2914, #2921, #2927, #2932.
When running on Windows via `uv run python tests/measure_esp32s3_opt_ins.py`,
the previous `subprocess.run(["bash", "compile", ...])` failed with:
WSL ERROR: CreateProcessCommon:818: execvpe(/bin/bash) failed:
No such file or directory
`bash` is not on PATH in a non-WSL Windows Python (the WSL relay-only
bash on the default PATH does not provide `/bin/bash`). The project
ships a `compile.bat` Windows wrapper for the same reason
`ci/bloat.py` uses it. Mirror that pattern.
For `bash bloat`, there is no `bloat.bat` shim — the bash wrapper is
a one-line `uv run ci/bloat.py "$@"`, so we invoke the Python entry
point directly on Windows.
Both branches use absolute paths via `PROJECT_ROOT` because Windows
`subprocess.run` does not auto-resolve `.bat` files relative to the
`cwd` argument.
## Files
- tests/measure_esp32s3_opt_ins.py:
- New `_run_compile_cmd(example)` helper picks bash compile (Linux)
or absolute-path compile.bat (Windows).
- New `_run_bloat_cmd()` helper picks bash bloat (Linux) or
`uv run ci/bloat.py` (Windows).
- `run_compile` / `run_bloat` use the helpers.
## Verification
- `uv run python tests/measure_esp32s3_opt_ins.py --config baseline`
on Windows: succeeded; produced `total_flash = 339,962 B` (matches
the current pinned baseline).
- bash lint -> all linters pass.
Refs #2886, #2935, #2906, #2934.
…) (#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.
tools(bloat): ship tests/measure_esp32s3_opt_ins.py multi-config audit driver
Closes #2905.
Ships a CLI driver that builds the ESP32-S3 NEOPIXEL Blink under each
release-mode opt-in combo from #2886, runs
bash bloat esp32s3against each ELF, and emits a Markdown comparison table sized to drop
straight into the priority table in
docs/SLIM_ESP32S3.md.The script is the bridge between the SLIM doc's projected (📊)
entries and the measured (✅) ones. A follow-up doc PR runs the
script, captures the table, and flips 📊 → ✅ for the rows backed by
measurement.
What ships
tests/measure_esp32s3_opt_ins.py--config {baseline|stage2|stage3|stage4|stack|all},--example Blink,--out compare.md,--keep-platformio-ini-backup.agents/docs/binary-size-analysis.mdConfig matrix
baselinestage2-DFASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT=1stage3+ tools/sdkconfig_for_smallest_fastled.defaultsstage4-DFASTLED_RMT_STATIC_ALLOCATION=1stackSafety properties
platformio.ini→platformio.ini.bak. SIGINT / SIGTERM handlers restore the filebefore exit;
finally:block restores on any other exit path.The backup is deleted on clean exit unless
--keep-platformio-ini-backupis set.flavor of INI carries continuation lines and
${var.x}interpolations that
configparsermangles. The script only patchesthe
[env:esp32s3]block via a regex that matches up to the next[env:header (or EOF) — well-defined in practice.report.jsongetscopied to
report.<config>.jsonin the same dir, so the per-symboldata is preserved for
.claude/symbolaudit/diff.pycomparisons.Verification
bash lint→ all linters pass (Python via ruff + ty, C++, JS).The 6 pre-existing
tywarnings aboutos.systemare in unrelatedCI scripts; not introduced by this PR.
[env:esp32s3]block inplatformio.ini(extendsenv:generic-esp,carries
board_build.flash_size,board_build.partitions,build_flags). The regex correctly identifies the block boundary.comparison table that the follow-up doc PR consumes; that run
isn't in this PR because it's a separate measurement step
(~16 min for 5 configs × ~3-4 min each).
Out of scope
rows in
docs/SLIM_ESP32S3.md.tests/data/esp32s3_bloat_baseline.txt— the gatebaseline only tightens when a measured saving lands in
src/, notwhen a user-side build flag delivers the savings.
is a developer-facing local tool.
Refs #2886, #2905, #2904, #2900, #2898.
Summary by CodeRabbit
Documentation
Tests