Repository navigation
Description
Problem
PlatformIO (SCons) builds every translation unit (libraries, framework libraries, core, sketch) as nodes of one dependency graph at -j N, so any ready compile runs. fbuild's ESP32 orchestrator (crates/fbuild-build-esp/src/esp32/orchestrator/build.rs) runs them as serial stages. Each stage ends with a partly idle tail, and the next stage cannot start until it finishes.
| # | Stage (build.rs line on main) |
Serialization |
|---|---|---|
| 1 | Toolchain check → framework install check → log_toolchain_version (229, 240, 249) |
sequential awaits; spawns gcc --version every build |
| 2 | lib_deps compile, ensure_libraries (388) |
must finish before anything else compiles |
| 3 | …inside it, library_manager.rs:130 for lib in &installed |
one library at a time; files parallel within a library only |
| 4 | LDF / framework library selection (437) | waits for stage 2, but needs only lib_deps sources, not objects |
| 5 | Project-as-library (526) | separate serial step |
| 6 | Framework libraries (WiFi, FS, SPI…; 544; framework_libs.rs:136 loop) |
one library at a time; must finish before core starts |
| 7 | Core + sketch (750–776) | the only stage already on a shared pool (#1545), with boot artifacts overlapped (#1548) |
| 8 | Local lib/ libraries (826) |
runs after core/sketch, not alongside |
| 9 | embed_files (851), compile DB (867) |
small, serial before link |
| 10 | Link → convert/size | matches PlatformIO (the link must wait) |
bench/blink has no libraries, so stages 2–6 and 8 are empty and the benchmark does not show this. A FastLED project pays for all of it on every cold build: ~30 FastLED unity TUs one library at a time, then 5 framework libraries one at a time, then core + sketch.
Proposal
Extend the #1545 pattern (compile_phases::compile_core_and_sketch with one Arc<Semaphore>) to the whole build:
- Resolve first, compile later. Collect every library's sources and include dirs (
lib_deps, project-as-lib, LDF-selected framework libs, local libs), then run library selection on sources. It does not needlib_depsobjects. - One job pool. Submit every TU from every stage to a single FIFO semaphore, capped globally by the zccache per-core gate (perf: let the daemon's zccache run one compiler per core #1546), and ordered by
dispatch_rank(C++ first, perf(build): dispatch C++ translation units before C and assembly #1553/fix(build): take compile permits in dispatch order #1558). Within that, put the longest TUs first, e.g. the FastLED unity files. - Archive per library as soon as its objects are done. Each archive depends only on its own objects. The link waits on all archives, the core objects and the sketch.
- Remove the per-library
forloops inlibrary_manager.rsandframework_libs.rs, or turn them into producers that feed the pool. - Small items: run the toolchain and framework
ensure_installedconcurrently, and cache thegcc --versionprobe per toolchain path.
Correctness constraints to keep:
- Per-library flags and include dirs, and
library.jsonbuild flags. - Library-selection shadowing rules.
- Archive order on the link line.
.cmdhashrebuild signatures.- Fail-fast on the first compile error, with the join/drain soundness in
parallel.rs.
Expected impact
For FastLED sketches on ESP32, the cold build should approach one parallel phase bounded by (total TU CPU ÷ cores). Today it is the sum of each stage's makespan plus its idle tail. For blink, nothing changes.
Acceptance
- A FastLED example cold build (e.g.
DemoReel100, esp32s3) withFBUILD_PERF_LOG_JSONshows a single compile phase, and a process sampler shows ≥ N-1 compilers busy throughout. - Before/after wall-time numbers are recorded (median of 3, 4 cores), alongside PlatformIO's phases from the benchmark's
pio run -vbreakdown (bench: break PlatformIO cold builds into phases for A/B with fbuild #1557). - The same firmware as before: identical selected libraries and link inputs.
Follow-up to #1537.
Sub-issues
Collapse Sub-issuesSub-issues
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
zackees commentedon Sep 28, 2026
Scope update: centralize the scheduler in the engine so every platform gets it
This is not an ESP32-only change. The unified job pool belongs in
fbuild-build-engine, in the sharedpipeline, and every orchestrator should use it. The ESP32 orchestrator moves onto it too rather than keeping a private scheduler.Where the serialization lives today
lib_depscompile before anything else, one library at a time (library_manager.rs:130)fbuild-library/pipeline/library.rspipeline/sequential.rs/compile_project_as_libraryframework_libs.rs:136)lib/libraries after core/sketch (build.rs:826)lib_depsobjectsensure_installedplus agcc --versionprobe on every buildPlan
pipeline::schedule(new module infbuild-build-engine). It takes a set of compile units (source, output, flags/overlay, owning target) grouped into targets: core, variant, sketch, eachlib_depslibrary, each framework library, local libraries, and project-as-library.Semaphore, ordered bydispatch_rankand taking permits in dispatch order (perf(build): dispatch C++ translation units before C and assembly #1553/fix(build): take compile permits in dispatch order #1558). zccache's per-core gate (perf: let the daemon's zccache run one compiler per core #1546) stays the global cap.'static-borrow soundness rule fromparallel.rs.ensure_librariesresolves and installs libraries and returns their sources, include dirs and flags without compiling them. Library selection runs on sources. The scheduler does all the compiling.pipeline/sequential.rsbuilds the target set and calls the scheduler. This covers all ~14 shared orchestrators (AVR, ARM families, RP2040, ESP8266, CH32V…) with no per-platform code.compile_phases.rsand the per-library loops inframework_libs.rs/library_manager.rsgo away.ensure_installed, and a cachedgcc --versionprobe keyed by toolchain path.Testing
Unit tests cover the scheduler completely, in the engine, with a fake
Compilerlikeparallel.rs'sTracingCompiler:.cmdhash) and empty targets are handled;Light end-to-end checks only on two platforms:
bench/blink.bench/blink -e unoplus one AVR sketch with alib_depslibrary.Each should show the same selected libraries and link inputs as before, with before/after cold times (median of 3, 4 cores).
perf(library): compile libraries on a shared job gate, concurrently (#…
perf(pipeline): compile lib_deps and project-as-library in the shared…
perf(esp32): compile everything in one job pool (#1563)
fix(library): keep compile temp files out of the project; report exit…
fix(esp32): keep #include_next headers out of the header farm (#1567)
perf(build): dispatch translation units longest-first using recorded …
zackees commentedon Sep 29, 2026
Done. Every stage compiles in one shared job pool on all platforms, and the sub-issues found along the way are fixed.
PRs
fbuild-library: library compiles draw from a caller-suppliedJobGate, with permits taken in dispatch order and fail-stop.ensure_librariesis split intoresolve_librariesplus aLibraryCompilePlanthat compiles every library concurrently. Also fixes #1560: a stale-archive shortcut meant edited local or symlinkedlib_depsnever rebuilt.lib_depsand project-as-library compile on the pipeline'scompile_slots, joined with core, variant, sketch and local libraries.lib_deps, framework libraries (all at once), project-as-library, core + sketch and local libraries run in onetokio::join!on one gate, plus concurrent package install.#include_nextheaders found beside a quoted includer brokeassert.h.Before / after
Before is
mainat4b695966, before this work. After ismainatc601d821. Each build was cold (fbuild clean cacheplus--clean), pinned to 4 cores, alternating before/after, median of 3. The firmware sha256 is identical before and after for every project.unobench/blinkESP32-S3 (no libraries; 6 trials)bench/blinkunoThe first "after" FastLED ESP32-S3 trial ran with no duration history and took 28.7 s, so almost all of the gain comes from the shared pool itself. The remaining floor is FastLED's single ~17 s
fl.fx+.cppunit plus the link. Library-free sketches (blink) were expected to be unaffected, and they are.