terraform: extract module call bodies once in buildChildModules#2576
Draft
bendrucker wants to merge 1 commit into
Draft
terraform: extract module call bodies once in buildChildModules#2576bendrucker wants to merge 1 commit into
bendrucker wants to merge 1 commit into
Conversation
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
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.
Same quadratic as #2575, in the vendored config builder.
buildChildCtxcalledPartialContentover the whole parent body once per child (terraform/config.go), insidethe per-call loop in
buildChildModules.The fix mirrors #2575: load every child module first, extract all module-call arguments in
a single
PartialContentpass, then build each child context from the pre-extractedbodies. 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 theexact structural mirror of the tflint-side fix, and it is covered by the existing
terraformconfig tests plus the inspection integration suite.Stacked on #2575.