velxio/backend/scripts
David Montero Crespo f15834d14d perf(compile): memoize ldgen - 41% of every ESP-IDF build was re-parsing linker fragments
Profiled a one-file ESP-IDF compile on staging: 36.7 s total, of which
ldgen.py alone was 15.2 s - consistently, on every single build. It
re-parses all 48 component linker.lf fragments with pyparsing each time
(3.8 M _parseNoCache calls; parse_fragment_file 15.6 s under cProfile),
even though its output depends only on the sdkconfig and those
fragments, never on the user's source.

pyparsing's packrat cache was tried first and made it WORSE (15.2 s ->
27.4 s), so the fix is memoizing the whole run: a wrapper hashes the
argv plus the CONTENT of every file it references and reuses the
generated linker script when they are unchanged. Verified on staging:
15.2 s -> 0.08 s on a hit, byte-identical output, and correctly missing
when the sdkconfig or any linker.lf changes (restoring the sdkconfig
hits again - it is content-addressed, not mtime-based). Any surprise
falls through to the untouched upstream script, so a build can never
break because of the cache.

New hand-written code on the ESP32-P4 lane: 36.7 s -> 11.5 s.
2026-08-20 05:29:56 +02:00
..
__init__.py feat: persist multi-board projects + add auto-save 2026-05-01 13:43:33 -03:00
backfill_boards_2026_05.py feat: persist multi-board projects + add auto-save 2026-05-01 13:43:33 -03:00
ldgen_cache.py perf(compile): memoize ldgen - 41% of every ESP-IDF build was re-parsing linker fragments 2026-08-20 05:29:56 +02:00