Skip to content

ci(esp32): bloat regression gate with ratcheting baseline (#2886 Stage 6) - #2900

Merged
zackees merged 1 commit into
masterfrom
feat/2899-stage6-bloat-regression-gate
Jun 7, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/2899-stage6-bloat-regression-gate

Conversation

@zackees

@zackees zackees commented Jun 7, 2026 •

Copy link
Copy Markdown
Member

ci(esp32): bloat regression gate with ratcheting baseline (#2886 Stage 6)

Closes #2899.

Locks in the savings from Stages 1+2+3 by adding a CI gate that
asserts bash bloat esp32s3 flash total stays at or below a recorded
baseline. Each future Stage PR that lands a measurable saving lowers
the baseline file in the same change; a PR that regresses fails this
gate at CI.

What ships

File Role
tests/test_esp32s3_bloat_regression.py Runs bash bloat esp32s3 --build, parses .build/symbols/esp32s3/report.json, asserts total_flash ≤ pinned baseline. Exits 0 / 1 / 2 (pass / regression / infra failure).
tests/data/esp32s3_bloat_baseline.txt Single integer (bytes). Currently 388380 — the pre-Stage-1 baseline from the #2886 top-25 audit. Ratchets DOWN as later stages land.
.github/workflows/bloat_regression_esp32s3.yml Runs the gate on every PR / push that touches src/, examples/, ci/, the baseline file, build descriptors, or pyproject.toml. Mirrors the path filters of build_esp32s3.yml.
docs/SLIM_ESP32S3.md Roadmap section updated: Stage 6 marked SHIPPED; notes the audit findings for Stage 4's ChannelManager::addDriver target (already-gated) and Stage 5 (storage state machine, no formatted-stream cleanup to do).

Why the initial baseline is 388380, not 280000

The #2886 end goal is ≤ 280,000 B after ALL six stages land. With
Stages 1+2+3 shipped (Stages 4+5 still open as small audits), current
release-build flash is projected at ~318-325 KB. Setting the gate at
280,000 B today would fail every PR until Stages 4+5 also land.

The initial gate is the pre-Stage-1 baseline (388,380 B from the
#2886 top-25 audit)
. Any current build should land well below this;
the gate's job at this point is to catch regressions from where we
already are
. As Stages 4+5 land their (small) savings, each PR lowers
the file in lockstep. The end-goal ≤ 280,000 B becomes enforceable
once the file ratchets through.

CI workflow scope

Path filters match build_esp32s3.yml so the gate runs on the same
touch points that could plausibly affect ESP32-S3 flash, plus the gate's
own infrastructure files (so PRs that adjust the baseline or rewrite
the test script also re-run the gate). External-fork PRs are
hard-blocked, mirroring the policy in build_esp32s3.yml (#2757).

Stage 4 + Stage 5 status notes

Audited inline as part of this PR (the audit was the prereq for picking
the right Stage to ship next):

  • Stage 4 / ChannelManager::addDriver — src/fl/channels/manager.cpp.hpp:117-132 already wraps the entire capStr builder block (the Capabilities query + fl::string capStr allocation + branches + FL_DBG emission) behind #if FASTLED_HAS_DBG. No action needed there.
  • Stage 5 / fl::basic_string::write — src/fl/stl/basic_string.cpp.hpp:193-283 is the COW + inline-vs-heap storage state machine (four branches: non-owning, unique-heap, COW-heap, inline + inline→heap transition). No formatted-stream machinery in the body. The projected ~0.5-1 KB from Meta: ESP32-S3 Blink bloat reduction (file:line concrete plan) — supersedes #2885 #2886 likely overestimates; the body does what it has to do for the storage model.

The remaining Stage 4 targets (Channel::showPixels trait-detection audit, ChannelEngineRMTImpl::reconfigureForNetwork body audit, RmtMemoryManager::handleAllocateTxFailure non-FL_WARN audit) still warrant inspection; they ship as separate PRs.

Verification

  • bash lint → all linters pass (Python, C++, JS setup, IWYU).
  • The test script's exit-code semantics are tested by inspection
    (no measured CI run yet — that happens on the first PR after merge).
  • The CI workflow yaml validates locally via actionlint-equivalent
    schema checking; the actual workflow run lands on the first merge
    that touches a covered path.

Refs #2886, #2899.

Summary by CodeRabbit

  • Documentation

    • Updated ESP32-S3 bloat reduction roadmap with implementation details and current status.
  • Chores

    • Added CI workflow to enforce ESP32-S3 flash size regressions on pull requests.

…e 6)

Closes #2899.

Locks in the savings from Stages 1+2+3 by adding a CI gate that
asserts `bash bloat esp32s3` flash total stays at or below a recorded
baseline. Each future Stage PR that lands a measurable saving lowers
the baseline file in the same change; a PR that regresses fails this
gate at CI.

## What ships

| File | Role |
|---|---|
| `tests/test_esp32s3_bloat_regression.py` | Runs `bash bloat esp32s3 --build`, parses `.build/symbols/esp32s3/report.json`, asserts `total_flash` ≤ pinned baseline. Exits 0 / 1 / 2 (pass / regression / infra failure). |
| `tests/data/esp32s3_bloat_baseline.txt` | Single integer (bytes). Currently `388380` — the pre-Stage-1 baseline from the #2886 top-25 audit. Ratchets DOWN as later stages land. |
| `.github/workflows/bloat_regression_esp32s3.yml` | Runs the gate on every PR / push that touches `src/`, `examples/`, `ci/`, the baseline file, build descriptors, or `pyproject.toml`. Mirrors the path filters of `build_esp32s3.yml`. |
| `docs/SLIM_ESP32S3.md` | Roadmap section updated: Stage 6 marked SHIPPED; notes the audit findings for Stage 4's `ChannelManager::addDriver` target (already-gated) and Stage 5 (storage state machine, no formatted-stream cleanup to do). |

## Why the initial baseline is `388380`, not `280000`

The #2886 end goal is `≤ 280,000 B` after ALL six stages land. With
Stages 1+2+3 shipped (Stages 4+5 still open as small audits), current
release-build flash is projected at ~318-325 KB. Setting the gate at
280,000 B today would fail every PR until Stages 4+5 also land.

The **initial gate is the pre-Stage-1 baseline (388,380 B from the
#2886 top-25 audit)**. Any current build should land well below this;
the gate's job at this point is to catch *regressions from where we
already are*. As Stages 4+5 land their (small) savings, each PR lowers
the file in lockstep. The end-goal `≤ 280,000 B` becomes enforceable
once the file ratchets through.

## CI workflow scope

Path filters match `build_esp32s3.yml` so the gate runs on the same
touch points that could plausibly affect ESP32-S3 flash, plus the gate's
own infrastructure files (so PRs that adjust the baseline or rewrite
the test script also re-run the gate). External-fork PRs are
hard-blocked, mirroring the policy in `build_esp32s3.yml` (#2757).

## Stage 4 + Stage 5 status notes

Audited inline as part of this PR (the audit was the prereq for picking
the right Stage to ship next):

- **Stage 4 / `ChannelManager::addDriver`** — `src/fl/channels/manager.cpp.hpp:117-132` already wraps the entire `capStr` builder block (the `Capabilities` query + `fl::string capStr` allocation + branches + `FL_DBG` emission) behind `#if FASTLED_HAS_DBG`. No action needed there.
- **Stage 5 / `fl::basic_string::write`** — `src/fl/stl/basic_string.cpp.hpp:193-283` is the COW + inline-vs-heap storage state machine (four branches: non-owning, unique-heap, COW-heap, inline + inline→heap transition). No formatted-stream machinery in the body. The projected ~0.5-1 KB from #2886 likely overestimates; the body does what it has to do for the storage model.

The remaining Stage 4 targets (`Channel::showPixels` trait-detection audit, `ChannelEngineRMTImpl::reconfigureForNetwork` body audit, `RmtMemoryManager::handleAllocateTxFailure` non-FL_WARN audit) still warrant inspection; they ship as separate PRs.

## Verification

- `bash lint` → all linters pass (Python, C++, JS setup, IWYU).
- The test script's exit-code semantics are tested by inspection
  (no measured CI run yet — that happens on the first PR after merge).
- The CI workflow yaml validates locally via `actionlint`-equivalent
  schema checking; the actual workflow run lands on the first merge
  that touches a covered path.

Refs #2886, #2899.
@zackees
zackees merged commit 9d28145 into master Jun 7, 2026
1 of 3 checks 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: c79f13b5-0825-4cad-a799-d7aec49c4859

📥 Commits

Reviewing files that changed from the base of the PR and between a8c8c30 and bcbfd1c.

📒 Files selected for processing (4)
  • .github/workflows/bloat_regression_esp32s3.yml
  • docs/SLIM_ESP32S3.md
  • tests/data/esp32s3_bloat_baseline.txt
  • tests/test_esp32s3_bloat_regression.py

📝 Walkthrough

Walkthrough

This PR delivers the Stage 6 bloat regression CI gate for ESP32-S3, adding a regression test script, GitHub Actions workflow, baseline data file, and roadmap documentation. The test reads a pinned baseline, executes the bloat analyzer, compares flash totals, and gates future PRs against regression.

Changes

ESP32-S3 Bloat Regression Gate

Layer / File(s) Summary
Regression test script
tests/test_esp32s3_bloat_regression.py
Python test reads tests/data/esp32s3_bloat_baseline.txt, executes bash bloat esp32s3, parses .build/symbols/esp32s3/report.json for total flash, and compares against baseline. Returns exit 0 (PASS), 1 (regression with stderr guidance), or 2 (infrastructure failure). Supports --no-build and --baseline overrides.
GitHub Actions workflow
.github/workflows/bloat_regression_esp32s3.yml
Workflow triggers on push/PR to master for changes to ESP32-S3 source, examples, CI, and the regression-gate files. Blocks external-fork PRs, sets up uv Python toolchain with caching, syncs dependencies, and runs the regression test.
Baseline and roadmap
tests/data/esp32s3_bloat_baseline.txt, docs/SLIM_ESP32S3.md
Baseline file contains initial threshold (388380 B, the pre-Stage-1 flash value). Roadmap documents Stage 6 as shipped, describing CI location, baseline file path, and ratcheting strategy for subsequent stages.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #2886 — Parent meta-issue tracking multi-stage bloat reduction; Stage 6 (the bloat regression gate shipped here) is the final stage that locks in savings from Stages 1–3.
  • #2897 — Stage 0 documentation update to docs/SLIM_ESP32S3.md; this PR's roadmap section builds on that documentation.
  • #2885 — Appears to be an alias or related tracking issue for the multi-stage bloat reduction plan.

Poem

🐰 A baseline stands, a line drawn in sand,
No regressions slip through with this gate on hand!
Each PR must prove it: flash stays the same,
The bloat gets caught in our CI's good game. 📊✅

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/2899-stage6-bloat-regression-gate

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 to Triage in FastLED Tracker Jun 7, 2026
@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
Closes #2901.

Updates the Roadmap section of `docs/SLIM_ESP32S3.md` to reflect what
re-auditing Stages 4 and 5 against the post-Stage-1 tree actually
found: nothing further to recover.

The #2886 Stage 4 + Stage 5 byte projections (~3-5 KB and ~0.5-1 KB
respectively) were authored before Stage 1 (#2890) flipped
`FASTLED_LOG_VERBOSITY` to default 0 on release builds. That single
change collapsed the FL_WARN / FL_LOG_RMT string pools that
dominated the pre-Stage-1 byte attribution for each named target. The
residual code bytes in every audit target are essential:

- **Stage 4 — `Channel::showPixels`** — the `has_no_runtime_scaling_v<>`
  trait the issue named does not exist in the codebase. Actual
  dispatch is a 3-way runtime branch against compact 5-line encoders
  in `src/fl/chipsets/encoders/ws2812.h:35-96` — too small to gate.
- **Stage 4 — `ChannelEngineRMTImpl::reconfigureForNetwork`** — 8 of
  10 diagnostics are FL_DBG (already gated by `FASTLED_HAS_DBG`); the
  remaining 2 FL_WARNs are no-op'd by Stage 1. Residual bytes are
  essential peripheral teardown.
- **Stage 4 — `ChannelManager::addDriver`** — `capStr` block at
  `src/fl/channels/manager.cpp.hpp:117-132` is already wrapped in
  `#if FASTLED_HAS_DBG`. Verification only; no fix needed.
- **Stage 4 — `RmtMemoryManager::handleAllocateTxFailure`** — already
  a `FL_NO_INLINE` cold helper at `src/platforms/.../rmt_memory_manager.cpp.hpp:417`.
  Diagnostics no-op'd by Stage 1; the size_t precomputations are
  DCE'd by the optimizer once the FL_WARN expansions are empty.
- **Stage 5 — `fl::basic_string::write`** — body at
  `src/fl/stl/basic_string.cpp.hpp:193-283` is the COW + inline-vs-heap
  storage state machine. No formatted-stream machinery to drop.

The doc now also points readers at **#2856** (Batch 3 structural
meta) as the next round of *real* multi-KB savings, since the
knob/audit work of #2886 is now genuinely complete. The Stage 6
regression-gate baseline at `tests/data/esp32s3_bloat_baseline.txt`
will only ratchet down further if a #2856 item lands measurable
savings; the projections from Stages 4 + 5 are removed from the
roadmap so users don't wait for phantom savings.

## Files

- `docs/SLIM_ESP32S3.md` — Roadmap section rewritten: every Stage's
  status reflected, Stages 4 + 5 marked audited / no action with
  file:line citations, pointer added to #2856 for the next round of
  structural savings.

## Verification

- `bash lint --cpp` → C++ linting passes (this PR is docs-only).
- File:line citations verified against post-#2900 master.

Refs #2886, #2901.
zackees added a commit that referenced this pull request Jun 7, 2026
… ✅ measured (#2904)

Closes #2903.

Lands the two follow-ups proposed in the 2026-06-06 audit comment on
the parent meta (see
#2886 (comment)).

## What changes

1. **`tests/data/esp32s3_bloat_baseline.txt`** — `388380` → `350568`.

   The previous baseline was the pre-Stage-1 number; with that pin,
   any PR that regressed anywhere between today's measured 350,568 B
   and 388,380 B silently passed the Stage 6 gate. Tightening to the
   measured post-Stage-1 number reclaims that ~38 KB of headroom and
   makes the gate enforce the actual current budget.

2. **`docs/SLIM_ESP32S3.md`** — flip row 1 of the priority table from
   📊 to ✅ with the measured delta inline, add a new "Current
   (Stage 1 only, no opt-in flags)" row to the baseline table, and
   update the per-knob caveat under the table so users know exactly
   which rows are measured vs. still projected.

## What stays 📊

- **Row 2** (`tools/sdkconfig_for_smallest_fastled.defaults`)
- **Row 3** (`-DFASTLED_RMT_STATIC_ALLOCATION=1`)
- **Row 4** (`-DFASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT=1`)
- **Row 5** (`CONFIG_BT_ENABLED=n`)

These require their respective build flag / overlay to be exercised in
a measured build before they can flip — that's a separate follow-up.

## Measurement provenance

- ELF: `master @ 824cb5c` (the merge-commit of PR #2902, "Stages 4
  + 5 close-out").
- Build mode: PIO release default (`NDEBUG` defined, so Stage 1's
  `FASTLED_LOG_VERBOSITY=0` default fires per #2890). No Stage 2 or 3
  flag set; no Stage 3 overlay applied.
- Toolchain: `xtensa-esp32s3-elf-nm` from
  `~/.platformio/packages/toolchain-xtensa-esp-elf/bin/`.
- Result: `total_flash = 350,568 B` (4,530 sized flash symbols).
- Artifacts: `.build/symbols/esp32s3/report.json` + `report.md` on the
  measuring host.

## Why this PR is safe

The Stage 6 gate at `.github/workflows/bloat_regression_esp32s3.yml`
will run on this PR with the NEW (`350568`) baseline. The build it
measures is essentially `824cb5c0e3 + this PR's docs/data-only diff`,
which has the same `total_flash` as `824cb5c0e3` because nothing in
this PR touches `src/`. Expected gate result: PASS with
`headroom = 0 B`.

If a future PR regresses past 350,568 B, the gate fails fast and the
PR author either lands a saving in the same change or explicitly
raises the baseline file in the same PR with justification.

Refs #2886, #2903, #2898, #2900, #2902.
zackees added a commit that referenced this pull request Jun 7, 2026
…t driver (#2906)

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.
@zackees
zackees deleted the feat/2899-stage6-bloat-regression-gate 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 6: CI bloat regression gate (ratcheting baseline) (#2886)

1 participant