Repository navigation
Speed up lbuild with template caching - #87
Merged
Merged
Conversation
5 tasks done
salkinium
force-pushed
the
feature/speedups
branch
from
September 29, 2026 17:30
5af0bea to
9e1ad81
Compare
salkinium
force-pushed
the
feature/speedups
branch
from
September 29, 2026 19:37
a86d904 to
58b8a99
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I tried to make lbuild faster with Python 3.14's free-threading, which kinda worked (2x for a single build), but in CI we already run one lbuild per CPU, so it didn't help at all, lol. The profiling on the way was a lot more useful though: more than 40% of the runtime was just Jinja2 compiling the same templates over and over again, since every module gets its own Jinja2 environment.
FileSystemBytecodeCacheshared by all modules and lbuild runs. It's stored in the per-user temp folder ($TMPDIR/_jinja2-cache-$UID), keyed by template path and source checksum, and the Jinja2 and lbuild versions are part of the filename so an upgrade starts fresh. If the temp folder is not usable, lbuild just compiles without the cache.env[…],env.query(…)andenv.has_module(…)did a full anytree glob from the root, ~1000-2000 times per build.add_modules_recursive, which skips ~96kfnmatchcalls.functools.cacheanyway). CI now tests 3.11 to 3.14 with the current GitHub Actions versions.test/all/cortex-m.xmland almost all ofmodm:**) on STM32H743.With modm on STM32H743ZIT6:
test/all/cortex-m.xmlmodm:**The cache works across targets too: after building the H743, an H723 compiled zero new templates and an F469 only 23. So the CI jobs should benefit a lot.
There's a follow-up that returns copies of cached query results (
feature/query-copy), since modules mutating the shared results is a real bug. But it breaks older modm versions on F7/H7, so it has to wait until modm-io/modm has the fix in a release.