Skip to content

Commit

Permalink
encoding/gocode: use many fewer go/packages.LoadMode bits
Browse files Browse the repository at this point in the history
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í <[email protected]>
Change-Id: I06cc023bedfee5cadf5313cf001b35bce9f41af3
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201336
Reviewed-by: Roger Peppe <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
mvdan committed Sep 17, 2024
1 parent 80a862c commit 99160fd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion encoding/gocode/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 99160fd

Please sign in to comment.