You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A schema cache was introduced as part of 0.16.0 release. memdb was also introduced to make operations above the state easier to handle. One side-effect of these changes was that we would create a full copy of every provider schema before storing that into memdb. This should have negligible impact on memory usage (as GC should cleanup the original copy), however because we make the copy using copystructure which in turn makes heavy use of the reflect library, copying these schemas consumes significant amount of CPU.
Reduce CPU spikes upon initial language server launch.
Proposal
Investigate whether replacing copystructure with explicit Copy() implementations on schema structures would help reduce the CPU usage as Go won't have to use the (presumably) costly reflection at runtime.
The text was updated successfully, but these errors were encountered:
FWIW I was able to obtain a very similar profile on my Mac with fresh 0.16.2 - at least percentage-wise. I'm unsure why the total CPU time spent is about half, but the profile clearly points to the same bottleneck.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Current Version
Background
A schema cache was introduced as part of
0.16.0
release. memdb was also introduced to make operations above the state easier to handle. One side-effect of these changes was that we would create a full copy of every provider schema before storing that into memdb. This should have negligible impact on memory usage (as GC should cleanup the original copy), however because we make the copy usingcopystructure
which in turn makes heavy use of thereflect
library, copying these schemas consumes significant amount of CPU.This can be seen from CPU profiles collected by @mattduguid as part of a debugging session per hashicorp/vscode-terraform#591 , where about 70% of the CPU is spent in
schemas.PreloadSchemasToStore()
and a big part of those 70% is spent inreflectwalk
.Use-cases
Reduce CPU spikes upon initial language server launch.
Proposal
Investigate whether replacing
copystructure
with explicitCopy()
implementations on schema structures would help reduce the CPU usage as Go won't have to use the (presumably) costly reflection at runtime.The text was updated successfully, but these errors were encountered: