kubectx icon indicating copy to clipboard operation
kubectx copied to clipboard

Very slow with large number of contexts

Open alvaroaleman opened this issue 1 year ago • 2 comments

Compared to the native kubectl config use-context $contextname, kubectl ctx is noticeable slower when operating on a kubeconfig with a large number of contexts (9.8k).

kubectx ctx needs around 1.3-1.4 seconds to switch a context versus the native kubectl config use-context needing 0.7-0.8s (n=3 for each, M1 Pro with Sonoma 14.4).

alvaroaleman avatar May 04 '24 21:05 alvaroaleman

Is this the Go based implementation or the Bash based implementation?

ahmetb avatar May 04 '24 23:05 ahmetb

It was the bash implementation, but the go implementation is only marginally faster, takes ~1.1 seconds

alvaroaleman avatar May 04 '24 23:05 alvaroaleman

To close the loop here: The limiting factor is yaml decoding and I think there is very little we can do to speed that up. I ended up writing a minimal version of a similiar CLI in rust which reduced the runtime to about 300 ms. That is still noticeable to me so I made that CLI write in json and naively check for json on decoding and use a json decoder if possible - That brought it down to about 30 ms.

alvaroaleman avatar Aug 08 '24 03:08 alvaroaleman