You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
loader: memoize includes to avoid re-expanding diamond include graphs
ApplyInclude re-parses and recursively re-expands an included file once per
include path that reaches it. When the same file is reached through more than
one path (a "diamond" in the include graph) this is quadratic-to-exponential:
a 24-level doubling graph loads the leaf 2^24 times. Monorepos that aggregate
per-target / per-project compose fragments hit this in practice (an ~80-service
federation took ~55s in `docker compose config`).
Memoize each loaded include model for the duration of a single load, keyed on
every input that determines it — resolved paths, working dir, project dir, and
effective environment — and hand out a deep copy on each hit. The merge into
the parent (importResources) still runs for every occurrence, so a same-file
`extends` in the including file still resolves and the result is identical to
loading each time; only the parse + recursive expansion is shared.
Keying on the working dir matters: the same file reached through two parents
can have a different relative base, yielding models with different relative
paths; reusing across bases would let the caller rebase an already-resolved
path. Cycle-safe: an include cycle is intrinsic to a node's subtree, so it is
detected on the node's first load, before it can be cached.
Adds a deep-diamond regression test (times out without the cache) and a
benchmark.
Signed-off-by: Davi de Castro Reis <davi@davi.eng.br>
0 commit comments