Skip to content

terraform: extract module call bodies once in buildChildModules#2576

Draft
bendrucker wants to merge 1 commit into
construction-perffrom
construction-perf-tf
Draft

terraform: extract module call bodies once in buildChildModules#2576
bendrucker wants to merge 1 commit into
construction-perffrom
construction-perf-tf

Conversation

@bendrucker

Copy link
Copy Markdown
Member

Same quadratic as #2575, in the vendored config builder. buildChildCtx called
PartialContent over the whole parent body once per child (terraform/config.go), inside
the per-call loop in buildChildModules.

The fix mirrors #2575: load every child module first, extract all module-call arguments in
a single PartialContent pass, then build each child context from the pre-extracted
bodies. Splitting load from build keeps every child registered on the parent before
evaluation, as the original did.

With #2575 already in place, this removes what remained of the superlinear cost. At 1000
module calls, construction time drops a further ~96% to ~150ms, memory ~97% to ~190 MiB,
allocations ~98% to ~1.6M. Taken together the two PRs move 1000-module construction from
roughly 7.1s and 14 GiB to 150ms and 190 MiB, and the curve is now linear in the number of
module calls.

This edits vendored terraform/ code, which we normally leave alone. The change is the
exact structural mirror of the tflint-side fix, and it is covered by the existing
terraform config tests plus the inspection integration suite.

Stacked on #2575.

buildChildCtx called PartialContent over the whole parent body once per child module, re-expanding every module block for each call. Combined with the per-call loop in buildChildModules this is quadratic in the number of module calls. Load all children first, extract every call's arguments in a single PartialContent pass keyed by call name, then build each child context from the pre-extracted bodies.

Together with the NewModuleRunners change, runner construction becomes linear: at 1000 module calls, time drops from ~7.1s to ~150ms and allocations from ~158M to ~1.6M.

Claude-Session: https://claude.ai/code/session_01SFtKL5iaFWPVDqdcyvPiCJ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant