-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inefficient startup #823
Labels
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug description
The Tanzu CLI has an inefficient startup which becomes slower and slower as the number of configured contexts increases.
pkg/config/init.go
makes a call toSyncContextsAndServers()
in itsinit()
function; this meansSyncContextsAndServers()
is called every time the CLI is executed. Within theSyncContextsAndServers()
function, there is a loop that iterates over all the configured contexts, and for each one a call toconfig.SetContext()
is made which will in turn persist the configuration. For eachtanzu
context, the configuration is persisted once, meaning writing to theconfig.yaml
file and theconfig-ng.yaml
file. For non-tanzu
contexts, the configuration is actually persisted twice, which means writing to files 4 times.I somehow accumulated 29 contexts in my configuration, which, because of the logic described above, make every command of the CLI noticeably slower.
Furthermore, the point of calling
SyncContextsAndServers()
is too handle certain scenarios where old plugins can modify theconfig.yaml
file incorrectly, and theSyncContextsAndServers()
will fix it. However, it the vast, vast majority of cases, this synchronization does nothing, although it still writes to the 2 configuration files multiple time and drastically slows down the CLI.Below shows that with 27 contexts, a simple help printout takes a full second, while if I remove all contexts, it drops to close to 0.2 seconds.
Expected behavior
The execution time of CLI commands should not be affected so dramatically by the number of contexts configured.
Steps to reproduce the bug / Relevant debug output
Run
time tanzu -h >/dev/null
and keep creating more contexts and see the time increase steadily.Any speed slower than 0.5 seconds starts being very noticeable when doing shell completion.
Output of
tanzu version
This started with CLI v1.2.0 and still affecting
main
today.Environment where the bug was observed (cloud, OS, etc)
Locally on my ARM64 Mac.
The text was updated successfully, but these errors were encountered: