improve plugins discovery performance #4120
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #3621
related to #3429
#3429 adds Cobra completion v2 support for commands and plugins. Since this change every invocation takes ~+60ms.
For
docker --version
:docker-19.03.15
docker-20.10.0
docker-20.10.12
docker-20.10.17
docker-20.10.23
docker-23.0.1
docker-dev-pr-3419-a4b6fe1
docker-dev-pr-3429-a09e61a
See the diff between
docker-dev-pr-3419-a4b6fe1
anddocker-dev-pr-3429-a09e61a
.Looking at the changes, we are now loading plugins for every invocation:
cli/cmd/docker/docker.go
Lines 230 to 233 in f5d698a
So the more plugins are in place in the user space, the worst it would be. And we have a lot of them in Docker Desktop atm:
- What I did
Instead of removing completion for plugins to fix the regression, we can slightly improve plugins discovery if we want to keep this feature.
We 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
I think a benchmark suite here that could be used by our plugins would be good at some point.
- How I did it
Spawn a goroutine for each iteration in the loop when listing plugins.
- How to verify it
Here is the benchmark result (see last row):
docker-19.03.15
docker-20.10.0
docker-20.10.12
docker-20.10.17
docker-20.10.23
docker-23.0.1
docker-dev-pr-3419-a4b6fe1
docker-dev-pr-3429-a09e61a
docker-dev-fix-perf-reg
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)