Skip to content
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

Open
marckhouzam opened this issue Oct 7, 2024 · 0 comments · May be fixed by #821
Open

Inefficient startup #823

marckhouzam opened this issue Oct 7, 2024 · 0 comments · May be fixed by #821
Labels
kind/bug PR/issue related to a bug needs-triage

Comments

@marckhouzam
Copy link
Contributor

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 to SyncContextsAndServers() in its init() function; this means SyncContextsAndServers() is called every time the CLI is executed. Within the SyncContextsAndServers() function, there is a loop that iterates over all the configured contexts, and for each one a call to config.SetContext() is made which will in turn persist the configuration. For each tanzu context, the configuration is persisted once, meaning writing to the config.yaml file and the config-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 the config.yaml file incorrectly, and the SyncContextsAndServers() 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.

$ tz version
version: v1.5.0
buildDate: 2024-09-26
sha: 9294e28
arch: arm64

$ tz context list | wc -l
[i] Use '--wide' to view additional columns.
      29

$ time tz -h> /dev/null
tanzu -h > /dev/null  0.91s user 0.07s system 105% cpu 0.924 total
$ mv ~/.config/tanzu/config* ~
overwrite /Users/kmarc/config-ng.yaml? (y/n [n]) y
overwrite /Users/kmarc/config.yaml? (y/n [n]) y
$ time tz -h> /dev/null
tanzu -h > /dev/null  0.06s user 0.02s system 37% cpu 0.222 total

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.

@marckhouzam marckhouzam added kind/bug PR/issue related to a bug needs-triage labels Oct 7, 2024
@marckhouzam marckhouzam linked a pull request Oct 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug PR/issue related to a bug needs-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant