perf(misconf): optimize work with context #6968
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.
Description
for_each
resource attribute is not added to the context because it cannot be accessed, but it can take up a lot of memory.GetAttr
method to accesscty.Object
attributes, instead of converting the object to a map.Unfortunately there is still the mergeVars function, which cannot be optimised due to some limitations. Because of the impossibility to modify
cty.Object
directly, it is necessary to convertcty.Object
into a map, modify it and create the object from the map again. With a large number of resources, such actions generate a large number of objects and take a decent amount of time due to checks and conversions inside thecty
package.Test config:
Before:
Memory usage is increasing, scans are not completed in a reasonable amount of time.
After:
/usr/bin/time -al ./trivy conf -q -f json -o report.json /Users/nikita/projects/trivy-test/diss-6958 29.68 real 40.85 user 0.69 sys 1221738496 maximum resident set size
Related issues:
Checklist