Skip to content

Commit 3ffbe4c

Browse files
committed
improve plugins discovery performance
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
1 parent f5d698a commit 3ffbe4c

File tree

7 files changed

+214
-12
lines changed

7 files changed

+214
-12
lines changed

cli-plugins/manager/manager.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package manager
22

33
import (
4+
"context"
45
"os"
56
"path/filepath"
67
"sort"
78
"strings"
9+
"sync"
810

911
"github.com/docker/cli/cli/command"
1012
"github.com/docker/cli/cli/config"
1113
"github.com/fvbommel/sortorder"
1214
"github.com/spf13/cobra"
15+
"golang.org/x/sync/errgroup"
1316
exec "golang.org/x/sys/execabs"
1417
)
1518

@@ -146,19 +149,31 @@ func ListPlugins(dockerCli command.Cli, rootcmd *cobra.Command) ([]Plugin, error
146149
}
147150

148151
var plugins []Plugin
152+
var mu sync.Mutex
153+
eg, _ := errgroup.WithContext(context.TODO())
149154
for _, paths := range candidates {
150-
if len(paths) == 0 {
151-
continue
152-
}
153-
c := &candidate{paths[0]}
154-
p, err := newPlugin(c, rootcmd)
155-
if err != nil {
156-
return nil, err
157-
}
158-
if !IsNotFound(p.Err) {
159-
p.ShadowedPaths = paths[1:]
160-
plugins = append(plugins, p)
161-
}
155+
func(paths []string) {
156+
eg.Go(func() error {
157+
if len(paths) == 0 {
158+
return nil
159+
}
160+
c := &candidate{paths[0]}
161+
p, err := newPlugin(c, rootcmd)
162+
if err != nil {
163+
return err
164+
}
165+
if !IsNotFound(p.Err) {
166+
p.ShadowedPaths = paths[1:]
167+
mu.Lock()
168+
defer mu.Unlock()
169+
plugins = append(plugins, p)
170+
}
171+
return nil
172+
})
173+
}(paths)
174+
}
175+
if err := eg.Wait(); err != nil {
176+
return nil, err
162177
}
163178

164179
sort.Slice(plugins, func(i, j int) bool {

vendor.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ require (
3737
github.com/theupdateframework/notary v0.7.1-0.20210315103452-bf96a202a09a
3838
github.com/tonistiigi/go-rosetta v0.0.0-20200727161949-f79598599c5d
3939
github.com/xeipuuv/gojsonschema v1.2.0
40+
golang.org/x/sync v0.1.0
4041
golang.org/x/sys v0.5.0
4142
golang.org/x/term v0.5.0
4243
golang.org/x/text v0.7.0

vendor.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ
524524
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
525525
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
526526
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
527+
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
528+
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
527529
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
528530
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
529531
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

vendor/golang.org/x/sync/LICENSE

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sync/PATENTS

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sync/errgroup/errgroup.go

Lines changed: 132 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ golang.org/x/net/internal/socks
276276
golang.org/x/net/internal/timeseries
277277
golang.org/x/net/proxy
278278
golang.org/x/net/trace
279+
# golang.org/x/sync v0.1.0
280+
## explicit
281+
golang.org/x/sync/errgroup
279282
# golang.org/x/sys v0.5.0
280283
## explicit; go 1.17
281284
golang.org/x/sys/execabs

0 commit comments

Comments
 (0)