Skip to content

perf(build): dispatch the longest translation units first using recorded compile durations #1564

Closed

Description

@zackees

Found while working on #1559.

With every compile now on one job pool (#1561, #1562, #1563), a FastLED sketch's cold build is bounded by its longest single translation unit. Measured solo compile times for FastLED's unity TUs (esp32s3):

TU seconds
fl.fx+.cpp 16.79
fl.gfx+.cpp 10.83
platforms+.cpp 8.23
fl.audio+.cpp 6.91
third_party+.cpp 5.87

29 TUs, 92 s of CPU in total.

The build cannot finish before fl.fx+.cpp finishes, so it must start in the first wave. Today the dispatch order is only C++ → C → asm, with source order within each group (#1553/#1558). A 17 s unit that happens to sort late starts after a full wave of other work. A 4-worker simulation of these 29 TUs gives 25.65 s in source order versus 23.21 s longest-first.

Static size is a poor predictor. platforms+.cpp pulls 2.3 MB of implementation, mostly #ifdef'd out for other chips, but compiles in 8 s. fl.fx+.cpp pulls 430 KB and takes 17 s.

Proposal

  • Record each TU's measured compile duration after it compiles: library TUs in library_compiler, core/sketch TUs in the engine's parallel.rs. Key the record on the source path plus the compile signature, in a small per-TU history under the fbuild cache root, so it survives clean of the build dir.
  • Dispatch each compile loop's work longest-first, by recorded duration. When there is no history, fall back to the current order (C++ first) and use the reachable implementation size (*.cpp/*.cpp.hpp includes) as a tie-breaker.
  • The history only affects order, never outputs or cache keys. A missing or corrupt record falls back silently.

Acceptance

  • Unit tests cover:
    • history round-trip;
    • longest-first order with history;
    • fallback order without history;
    • corrupt history ignored;
    • no effect on objects or signatures.
  • On FastLED DemoReel100 esp32s3, with history from one prior build, fl.fx+.cpp starts in the first wave.

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