Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/v1.13/ENHANCEMENTS-20250522-093102.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: ENHANCEMENTS
body: Performance fix for evaluating high cardinality resources
time: 2025-05-22T09:31:02.761383-04:00
custom:
Issue: "26355"
12 changes: 11 additions & 1 deletion internal/terraform/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,16 @@ func (d *evaluationStateData) GetResource(addr addrs.Resource, rng tfdiags.Sourc
instances[key] = value
}

// Proactively read out all the resource changes before iteration. Not only
// does GetResourceInstanceChange have to iterate over all instances
// internally causing an n^2 lookup, but Changes is also a major point of
// lock contention.
resChanges := d.Evaluator.Changes.GetChangesForConfigResource(addr.InModule(moduleConfig.Path))
instChanges := addrs.MakeMap[addrs.AbsResourceInstance, *plans.ResourceInstanceChange]()
for _, ch := range resChanges {
instChanges.Put(ch.Addr, ch)
}

// Decode all instances in the current state
pendingDestroy := d.Operation == walkDestroy
for key, is := range rs.Instances {
Expand All @@ -675,7 +685,7 @@ func (d *evaluationStateData) GetResource(addr addrs.Resource, rng tfdiags.Sourc
}

instAddr := addr.Instance(key).Absolute(d.ModulePath)
change := d.Evaluator.Changes.GetResourceInstanceChange(instAddr, addrs.NotDeposed)
change := instChanges.Get(instAddr)
if change != nil {
// Don't take any resources that are yet to be deleted into account.
// If the referenced resource is CreateBeforeDestroy, then orphaned
Expand Down