Skip to content

feat(ci): add bash bloat <board> wrapper for per-symbol flash analysis - #2883

Merged
zackees merged 1 commit into
masterfrom
feat/bash-bloat-wrapper
Jun 6, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/bash-bloat-wrapper

Conversation

@zackees

@zackees zackees commented Jun 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Codifies the lessons from the recent #2773 ESP32-S3 binary-size audit into a one-call tool so future agents don't re-discover the same gotchas (toolchain prefix per board, PIO output path layout, required --nm until fbuild#428 lands, fbuild symbols requiring fbuild >= 2.2.19, etc.).

Ships

  • bloat — bash entry-point matching the existing bash test / bash lint / bash compile convention.
  • ci/bloat.py — wrapper around fbuild symbols:
    • Auto-resolves the cross-toolchain nm from PIO packages based on BOARD_CHIP_MAP (esp32, esp32s2, esp32s3, esp32c3, esp32c6, esp32h2 today; entries are mechanical).
    • Auto-locates firmware.elf under .build/pio/<board>/.pio/build/<board>/ or .build/<board>/.
    • Writes BOTH report.json + report.md to .build/symbols/<board>/.
    • Prints a top-N collapsed-per-symbol-name table to stdout.
    • --build chains bash compile first.
    • Fails fast when fbuild lacks symbols (the 2.2.18 wheel doesn't carry it) with the exact upgrade path.
  • CLAUDE.md — new "Binary Size Analysis" section bakes in the 5 lessons learned + explicit "don'ts" to keep agents from re-implementing the wrapper or shelling out to nm directly.

Lessons baked into CLAUDE.md

  1. fbuild release lag — symbols merged after v2.2.18 wheel tag; rebuild from main until 2.2.19 ships.
  2. Map-derived synthesis (fbuild APA102 requires show() to be called twice for a correct update #427) is what makes .flash.rodata per-symbol; without it ~58 KB of NEOPIXEL FL_WARN strings bucket as anonymous against main.cpp.o.
  3. FASTLED_LOG_VERBOSITY=0 is the single biggest flash-bloat lever on ESP32-S3 (~43-58 KB).
  4. --nm still required until fbuild DWORD access must be aligned on ARM M0 #428 lands build-info-driven toolchain resolution.
  5. Diff two builds with the existing .claude/symbolaudit/diff.py.

Test plan

  • bash bloat esp32s3 --top 5 end-to-end against the Blink build: writes both artifacts, prints the top-5 summary table, reports 388,380 B flash / 37,460 B RAM / 4,591 symbols.
  • bash lint clean (python_pipeline + cpp + js all green).
  • Verified the released fbuild 2.2.18 wheel rejects the symbols subcommand, and the wrapper's assert_fbuild_has_symbols() fails fast with the upgrade message.

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • New binary size analysis tooling for examining firmware flash usage and identifying the largest contributing code components in compiled binaries across different board types.
  • Documentation

    • Added comprehensive documentation on binary size analysis workflows, including quick start options, supported boards, expected generated files, and best practices for bloat investigations.

Codifies the lessons from the recent #2773 ESP32-S3 binary-size audit
into a one-call tool so future agents don't re-discover the same
gotchas (toolchain prefix per board, PIO output path layout,
required `--nm` until fbuild#428 lands, map-derived synthesis
requiring fbuild >= 2.2.19, etc.).

## What ships

- **`bloat`** — bash entry-point matching the existing
  `bash test` / `bash lint` / `bash compile` convention.
- **`ci/bloat.py`** — Python wrapper around `fbuild symbols`:
  - Resolves the cross-toolchain `nm` from the PIO packages
    directory based on a `BOARD_CHIP_MAP` (esp32, esp32s2, esp32s3,
    esp32c3, esp32c6, esp32h2 today; entries are mechanical).
  - Locates the firmware ELF under either the PIO output
    (`.build/pio/<board>/.pio/build/<board>/firmware.elf`) or
    fbuild's native output (`.build/<board>/firmware.elf`).
  - Writes BOTH `report.json` (machine) and `report.md` (human,
    GitHub-flavoured tables) to `.build/symbols/<board>/`.
  - Prints a top-N table to stdout collapsing all (section, source)
    rows per demangled symbol name. Use `--no-summary` to suppress.
  - `--build` flag chains `bash compile <board> --examples Blink`
    first, for a one-shot fresh-build + analyse workflow.
  - **Fails fast** when the installed fbuild lacks `symbols` (the
    released 2.2.18 wheel does not carry it) with the exact upgrade
    path to take.

- **CLAUDE.md** — new "Binary Size Analysis" section that:
  1. Documents `bash bloat <board>` as the canonical entry point.
  2. Bakes in the 5 lessons learned: fbuild release lag, why
     map-derived synthesis matters, the `FASTLED_LOG_VERBOSITY=0`
     dominant lever, why `--nm` is still required, how to diff two
     builds via `.claude/symbolaudit/diff.py`.
  3. Adds an explicit "don'ts" list to keep agents from
     re-implementing the wrapper or shelling out to nm directly.

## Test plan

- [x] `bash bloat esp32s3 --top 5` end-to-end against the Blink
      build: writes both artifacts, prints the top-5 summary table,
      reports 388,380 B flash / 37,460 B RAM / 4,591 symbols.
- [x] `bash lint` clean (python_pipeline + cpp + js all green).
- [x] Verified the released fbuild 2.2.18 wheel rejects the
      `symbols` subcommand, and the wrapper's
      `assert_fbuild_has_symbols()` fails fast with the upgrade
      message.
@zackees
zackees merged commit b69ad0e into master Jun 6, 2026
6 of 7 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 6, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 6, 2026
@coderabbitai

coderabbitai Bot commented Jun 6, 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: 6634ccb8-afad-47ef-b658-ffd2856cf13d

📥 Commits

Reviewing files that changed from the base of the PR and between 84673c2 and bb091aa.

📒 Files selected for processing (3)
  • CLAUDE.md
  • bloat
  • ci/bloat.py

📝 Walkthrough

Walkthrough

Adds a complete binary bloat analysis toolchain: Python module ci/bloat.py that integrates fbuild symbols and nm-based symbol sizing for ESP32 boards, Bash wrapper script for CLI access, and documentation guiding users through firmware bloat audits.

Changes

Binary Bloat Analysis Tooling

Layer / File(s) Summary
Module setup & toolchain resolution
ci/bloat.py
Module docstring, imports, and board-to-chip mappings for ESP32 Xtensa/RISC-V variants; utility functions pio_packages_dir() and resolve_nm(board) locate PlatformIO toolchain packages and cross-compile nm binaries.
ELF discovery & fbuild integration
ci/bloat.py
find_elf() searches PlatformIO and fbuild output directories for firmware.elf; assert_fbuild_has_symbols() validates fbuild symbols availability; run_fbuild_symbols() executes fbuild symbols with nm override and top-N filtering.
Symbol aggregation & result formatting
ci/bloat.py
_AggBucket dataclass accumulates symbol sizes across sections and sources; print_summary() parses fbuild JSON results, aggregates by demangled name, and prints top-N table with rank, byte count, archive, object, symbol, and source.
Main orchestration & CLI interface
ci/bloat.py
main() parses board/example/top-N/build arguments, validates fbuild, optionally precompiles via bash compile, resolves toolchain and ELF paths, invokes bloat analysis, prints summary, and handles keyboard interrupts.
User-facing wrapper & documentation
bloat, CLAUDE.md
Bash script bloat sets error-exit and runs ci/bloat.py via uv; CLAUDE.md adds bash bloat <board> command reference and full Binary Size Analysis section covering usage, artifacts, and fbuild/toolchain constraints.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • FastLED/FastLED#2473: This PR directly implements the per-symbol binary bloat analysis infrastructure (ci/bloat.py + bloat wrapper) used to generate symbol-size breakdowns for ESP32 bloat reports.

Possibly related PRs

  • FastLED/FastLED#2823: The new ci/bloat.py integrates fbuild symbols for ELF-based analysis and handles correct nm/toolchain paths, addressing the same firmware artifact and symbol parsing concerns from the referenced PR's CI fixes.

Poem

🐰 Symbols sorted, sizes shown,
Bloat now audited, not unknown,
Xtensa, RISC-V, mapped with care,
Flash and RAM laid bare!

✨ 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/bash-bloat-wrapper

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.

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.

1 participant