From 99160fdf300e766985a8494947d684b1ce870071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 16 Sep 2024 14:06:58 +0100 Subject: [PATCH] encoding/gocode: use many fewer go/packages.LoadMode bits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We just need a package's name and type information. We don't need its syntax nor do we need to load dependencies, both of which multiply the cost of go/packages. `go generate` for encoding/gocode drops from ~1.55s to ~0.45s on my laptop after this change, which should help CI. Currently, its `go generate ./...` step with a warm Go cache is one of the slowest, clocking in at 12s. Slow generation steps are particularly harmful as they are sequential. Signed-off-by: Daniel Martí Change-Id: I06cc023bedfee5cadf5313cf001b35bce9f41af3 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201336 Reviewed-by: Roger Peppe TryBot-Result: CUEcueckoo Unity-Result: CUE porcuepine --- encoding/gocode/generator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/encoding/gocode/generator.go b/encoding/gocode/generator.go index 59e63d1e926..d51f8ebd03c 100644 --- a/encoding/gocode/generator.go +++ b/encoding/gocode/generator.go @@ -109,7 +109,7 @@ func Generate(pkgPath string, inst cue.InstanceOrValue, c *Config) (b []byte, er pkgName := inst.Value().BuildInstance().PkgName if pkgPath != "" { loadCfg := &packages.Config{ - Mode: packages.NeedName | packages.NeedFiles | packages.NeedCompiledGoFiles | packages.NeedImports | packages.NeedTypes | packages.NeedTypesSizes | packages.NeedSyntax | packages.NeedTypesInfo | packages.NeedDeps, + Mode: packages.NeedName | packages.NeedTypes | packages.NeedTypesInfo, } pkgs, err := packages.Load(loadCfg, pkgPath) if err != nil {