reduce instance change lookups in GetResource #37154
Merged
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.
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.