Skip to content

chore(bloat): ratchet baseline 388380 -> 350568 + flip Stage 1 row to ✅ measured - #2904

Merged
zackees merged 1 commit into
masterfrom
feat/2903-ratchet-baseline-flip-status
Jun 7, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/2903-ratchet-baseline-flip-status

Conversation

@zackees

@zackees zackees commented Jun 7, 2026 •

Copy link
Copy Markdown
Member

chore(bloat): ratchet baseline 388380 -> 350568 + flip Stage 1 row to ✅ measured

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

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.

Summary by CodeRabbit

  • Documentation

    • Updated ESP32S3 flash-size baseline measurements with new empirical verification
    • Confirmed measured flash savings for Stage 1 at -37,812 B
    • Adjusted projections to distinguish verified from projected results
  • Tests

    • Updated baseline measurement values in test data to reflect verified results

… ✅ measured

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.
@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: 7f4b0a23-8bc0-473f-8abd-1b8b2f75a209

📥 Commits

Reviewing files that changed from the base of the PR and between 824cb5c and 17beeab.

📒 Files selected for processing (2)
  • docs/SLIM_ESP32S3.md
  • tests/data/esp32s3_bloat_baseline.txt

📝 Walkthrough

Walkthrough

This PR ratchets the ESP32S3 flash-size regression baseline from 388,380 B to 350,568 B and updates documentation to reflect Stage 1 optimizations as measured rather than projected. The baseline is tightened to the current post-Stage-1 measured value, and the doc row now displays the confirmed 37,812 B savings with ✅ status.

Changes

ESP32S3 Bloat Baseline Ratchet and Documentation Update

Layer / File(s) Summary
Baseline ratchet and measured results documentation
tests/data/esp32s3_bloat_baseline.txt, docs/SLIM_ESP32S3.md
The regression-gate baseline is updated from 388380 to 350568 B. Documentation is updated to show the current measured baseline as 350,568 B flash, Stage 1 savings of 37,812 B confirmed (✅) on master @ 824cb5c0e3, and legend text clarified to mark only rows 2–5 as projected while row 1 is empirically verified.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

  • #2903: Directly linked issue describing the exact two follow-ups this PR delivers: ratchet the baseline and flip Stage 1 from 📊 to ✅ with measured numbers.
  • #2886: Parent meta issue that proposed these follow-ups via audit comment; this PR completes the loop opened by the bloat-reduction plan.
  • #2900: Stage 6 regression-gate PR; this PR ratchets that gate's baseline down to the measured value.
  • #2898: Stage 0 documentation PR; this PR updates those docs with measured results.

Poem

🐰 A baseline springs tighter than before,
350 kilobytes, measured and sure!
Stage 1's savings now shine in ✅ light,
No more projections—the numbers are right! 🎯

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/2903-ratchet-baseline-flip-status

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.

@zackees
zackees merged commit 447eaf5 into master Jun 7, 2026
1 of 3 checks passed
@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
…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 added a commit that referenced this pull request Jun 7, 2026
…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.
@zackees
zackees deleted the feat/2903-ratchet-baseline-flip-status 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.

Ratchet bloat baseline 388380 -> 350568 + flip 📊→✅ for Stage 1 in SLIM doc (#2886)

1 participant