Skip to content

perf(esp32): reuse the converted firmware image across fresh projects - #1902

Merged
zackees merged 1 commit into
mainfrom
agent/1894-firmware-bin-cache
Nov 5, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/1894-firmware-bin-cache

Conversation

@zackees

@zackees zackees commented Nov 5, 2026

Copy link
Copy Markdown
Member

Closes the remaining ~29% of a fresh-project ESP32 build. Follow-up to #1900 (link-output cache), part of #1894.

What was left

With #1900 merged, a fresh directory restores firmware.elf and the phase table on a warm-cache fresh dir is:

phase ms
link-restore 2
link-convert (esptool elf2image) 391
link-size 46
everything else ~890
total 1332

link-convert is the largest single phase left. firmware.bin is a pure function of the linked ELF plus the flash parameters passed to esptool, and the ELF is already byte-identical across fresh directories (verified by md5sum), so the converted image is reusable verbatim.

Change

New esp32/firmware_bin_cache module, consulted by Esp32Linker::convert_firmware after the per-project cache misses and before esptool is spawned:

  • key = ELF contents (never the path) + fingerprint version + chip + flash mode/frequency/size + esptool identity (provisioned path and length, or the caller-PATH hash for a bare esptool), so any input that changes the emitted bytes changes the key;
  • a hit copies the image through a temporary sibling (rename, EXDEV-safe fallback) and records the per-project .firmware_bin_cache.json, so the next build in that directory short-circuits before the shared cache;
  • a miss converts exactly as before and then stores the result;
  • strictly best effort: unreadable ELF, missing entry or any I/O error is a miss; entries prune oldest-first to 256 MiB;
  • cache root is <cache>/link-output/firmware-bin, i.e. the existing link-output cache root — no new plumbing at the build.rs call site.

Measured

Same host, warm framework cache, fresh ESP32-S3 DevKitC-1 blink directories (2.5.51, branch vs main):

main branch
link-convert 391 ms 4 ms
build total 1332 ms 845 ms
firmware.bin md5 9f1e391a… 9f1e391a… (identical)

Store path re-verified after the final refactor (fresh dir, cache cleared): convert 413 ms + entry written, next fresh dir convert 4 ms, same image.

Tests / gates

  • new tests: key path-independence and input sensitivity, store/restore round trip across directories, prune keeps the newest, and convert_firmware reuses without spawning esptool (the linker is given a non-existent esptool binary, so any spawn would fail);
  • RED: returning no key from the cache lookup fails the reuse test (0 passed; 1 failed);
  • fbuild-build-esp --lib: 218 passed / 0 failed / 1 ignored;
  • soldr clippy --workspace --all-targets -- -D warnings: rc 0;
  • soldr fmt --check: rc 0; test layout, dylint allowlists and platform boundary (rows=44; dylint_rows=43) all rc 0.

A fresh project directory whose objects are byte-identical to a previous
build now restores firmware.elf from the link-output cache (#1900), but the
remaining phase was `esptool elf2image`: 391 ms of a 1332 ms build, ~29% of
the total and the largest phase left (#1894).

firmware.bin is a pure function of the linked ELF plus the flash parameters
handed to esptool, and the ELF is already byte-identical across directories
(verified by md5), so the converted image is reusable verbatim. This caches
it beside the link-output cache, keyed on the ELF *contents* plus chip,
flash mode/frequency/size and the esptool binary identity; a hit copies the
image and skips the esptool spawn entirely. The restore also records the
per-project bin cache, so the next build in that directory takes the cheap
path too.

Measured on one host with a warm framework cache, fresh ESP32-S3 blink dirs
(2.5.51, branch vs main): link-convert 391 ms -> 4 ms, build total
1332 ms -> 845 ms, identical firmware.bin md5 across every directory.
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@zackees
zackees added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit c9b608e Nov 5, 2026
37 checks passed
@zackees
zackees deleted the agent/1894-firmware-bin-cache branch November 5, 2026 02:24
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant