Skip to content

Conversation

@jbardin
Copy link
Member

@jbardin jbardin commented May 22, 2025

Expanded resources always require fetching all instances for evaluation, but the changes data structure requires iterating over all instances for each call to GetResourceInstanceChange, so it turns out to be an n^2 operation. This wasn't very visible in most configs with relatively few numbers of instances, but when you have a resource with a large number of instances referencing another resource with a large number of instances (e.g. the second resource uses the first as the for_each argument), you end up with (n^2)^2 lookups. Because the instance changes are in a global structure, this single point of lock contention would hold up the entire plan.

I'm going to call #26355 closed on this one. It was the last major bottleneck, and gets the performance more inline with individual instance performance. Other fixes will have to be more at the language level, so would be out of scope for instance evaluation specifically.

Closes #26355.

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

jbardin added 2 commits May 22, 2025 09:18
Expanded resources always require fetching all instances for evaluation,
but the changes data structure requires iterating over all instances for
each call to GetResourceInstanceChange, so it turns out to be an n^2
operation. This wasn't very visible in most configs with relatively few
numbers of instances, but when you have a large number of instances
referencing another resource with a large number of instances (e.g. the
second resource uses the first as the for_each argument), you end
up with (n^2)^2 lookups. Because the instance changes are in a global
structure, this single point of lock contention would hold up the entire
plan.
@jbardin jbardin marked this pull request as ready for review May 22, 2025 13:45
@jbardin jbardin requested a review from a team as a code owner May 22, 2025 13:45
@jbardin jbardin merged commit fa387fc into main May 22, 2025
14 checks passed
@jbardin jbardin deleted the jbardin/resource-changes-perf branch May 22, 2025 14:38
@github-actions
Copy link
Contributor

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance issues when referencing high cardinality resources

2 participants