Add caching to various schema reading functions #15641
Closed
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.
This is a massive performance boost for larger, more complex (lots of nested Set) schemas. For a complex config it brings the time from >3hrs down to "instant".
This may not be the best solution to this problem, but it is a solution, and dramatically reduces the recursion that occurs. I suspect there is further caching that can be done within the
for
loop inaddrToSchema()
but I couldn't figure that out.Reproduction
I have created a "simple" provider to replicate the issue here: https://github.com/dshafik/terraform/tree/nested-schema-example
The provider (excepting the schema is literally one simple function:
As you can see it is effectively just a
schema.ResourceData.Get()
call. You may need togo get github.com/davecgh/go-spew/spew
for the dump to work, but you can obviously just removespew
call if you don't care about the output.With the example config it takes ~1 minute; and you can drastically reduce that time by commenting out the
option
blocks.Real
The actual schema is much bigger, but the schema definition doesn't seem to make a difference, it's entirely down to the config itself.
A full config (3hrs+ without this fix) can be seen here