Skip to content

perf(esp32): boot-artifacts spawns esptool elf2image on every cold build for a deterministic, cacheable output #1541

Closed

Description

@zackees

What

boot-artifacts runs esptool elf2image on every cold build to convert the framework's bootloader ELF into bootloader.bin, even though the output is a pure function of inputs that are already known and already content-addressed elsewhere in the build.

crates/fbuild-build-esp/src/esp32/orchestrator/boot_artifacts.rs:47-120: when the framework ships a bootloader ELF but no prebuilt bootloader.bin (the arduino-esp32 2.x layout used by [email protected]), the else branch at :89 builds esptool_elf2image_argv(...) and runs it, logging converted bootloader ELF → bootloader.bin at :108. partitions.bin / boot_app0.bin are already prebuilt copies, and gen_esp32part.py is only a fallback.

Why it matters

The output depends only on: the framework version, sdk_variant, flash mode, flash frequency, flash size, and the board's partition table — none of which are project state. Chip families that ship an ELF-only framework pay one esptool Python subprocess per cold build for a byte-identical result.

Measured 230 ms for the boot-artifacts phase on bench/blink -e esp32s3 (16-core Linux, via FBUILD_PERF_LOG_JSON); an earlier run on the same box measured 72–108 ms, so it varies with how warm the process/file caches are, but it is always a Python spawn.

Compared against PlatformIO's whole cold pre-compile budget (~0.80 s in #1537), this single un-cached step is a double-digit percentage of it.

Suspected fix

Content-address the bootloader.bin like the neighbouring framework-libs and core caches already are — key on (framework version, sdk_variant, flash mode/freq/size) and store the converted BIN — so a cold build copies instead of re-converting. Failing that, at least skip the conversion when a bootloader.bin is already present from a previous build of the same key.

Found while investigating #1537.

Activity

  1. zackees commented on Sep 28, 2026

    @zackees
    MemberAuthor

    Resolved by #1548, which takes the conversion off the critical path instead of caching its output.

    prepare_boot_artifacts (bootloader elf2image, partitions.bin, boot_app0.bin) now runs tokio::join!ed with the core and sketch compile fan-out rather than serially after the link. Where the ~110 ms went, by build type:

    A content-addressed bootloader.bin cache would only save CPU the scheduler already hides, and it would add a cache that has to be invalidated. Closing; if a profile ever shows this on a critical path again, the cache key described above is still the right design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions