-
Notifications
You must be signed in to change notification settings - Fork 2.1k
improve and load plugin command stubs when required #4129
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
Conversation
We are currently loading plugin commands stubs for every command invocation to add support for Cobra v2 completion. This cause a significant performance hit if there is a lot of plugins in the user space (7 atm in Docker Desktop): `docker --version` takes in current 23.0.1 ~93ms Instead of removing completion for plugins to fix the regression, we can slightly improve plugins discovery by spawning a goroutine for each iteration in the loop when listing plugins: `docker --version` now takes ~38ms Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
We are currently loading plugin command stubs for every invocation which still has a significant performance hit. With this change we are doing this operation only if cobra completion arg request is found. - 20.10.23: `docker --version` takes ~15ms - 23.0.1: `docker --version` takes ~93ms With this change `docker --version` takes ~9ms Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
b166b11 to
c39c711
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #4129 +/- ##
==========================================
- Coverage 59.16% 59.12% -0.05%
==========================================
Files 287 287
Lines 24716 24745 +29
==========================================
+ Hits 14623 14630 +7
- Misses 9209 9230 +21
- Partials 884 885 +1 |
|
cc @laurazard |
| // We add plugin command stubs early only for completion. We don't | ||
| // want to add them for normal command execution as it would cause | ||
| // a significant performance hit. | ||
| err = pluginmanager.AddPluginCommandStubs(dockerCli, cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if there is a completion arg, why do we need to list all the plugins? Most likely the command is only for a specific plugin. Asking for follow-up, not a blocker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we need to list completion values for plugins too so they have to be registered first in cobra root command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only when the args is docker. Not when it is already docker buildx. This is not that important as only affects the completion path but ideally it shouldn't be that adding more plugins makes completion for another plugin slower.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes indeed, we could improve this.
laurazard
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and changes LGTM
|
Could we have a cherry pick label for this? |
|
THANKS! Let's bring this one in 👍 |
fixes #3621
related to #3429
closes #4119
closes #4120
- What I did
We are currently loading plugin commands stubs for every command invocation to add support for Cobra v2 completion. This causes a significant performance hit if there are a lot of plugins in the user space (7 atm in Docker Desktop):
docker --versiontakes ~93ms currently:docker-20.10.12docker-20.10.17docker-20.10.23docker-23.0.1docker-dev-pr-3419-a4b6fe1docker-dev-pr-3429-a09e61aInstead of removing completion for plugins to fix the regression as suggested in #4119, we can slightly improve plugins discovery by spawning a goroutine for each iteration in the loop when listing plugins:
docker --versionnow takes ~38msBut there is still a significant performance hit compared to
20.10.23. With second commit we are now loading plugins only if cobra completion arg request is found and also make sure plugin command stubs are loaded once.With this change
docker --versionnow takes ~9ms:docker-20.10.12docker-20.10.17docker-20.10.23docker-23.0.1docker-dev-pr-3419-a4b6fe1docker-dev-pr-3429-a09e61adocker-dev-fix-perf-reg-2We should also look if every plugin we currently ship doesn't introduce performance regressions when invoked through the plugin manager in
cli/cli-plugins/manager/candidate.go
Line 22 in f5d698a
Full benchmark can be seen at https://github.com/crazy-max/docker-cli-bench/blob/main/bench.md
- How to verify it
Check completion still working for commands and plugins per #3429:
Check a plugin help output:
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)