go: x/tools/cmd/stringer: stringer should not use go/types

It takes much longer to run stringer on a program than to compile it. Stringer should be nearly instantaneous, but I suspect the new importer technology is killing performance. Something certainly is.

At tip, wiith a freshly written file, so the build cache has the dependencies but not the output of building list.go itself:

% go version
go version devel +47be3d49c7 Thu May 10 23:19:40 2018 +0000 darwin/amd64
% cat list.go
package main

import (
	"gopkg.in/src-d/go-license-detector.v2/licensedb/filer"
)

func main() {
}

type Type int

const (
	Other Type = iota
	A
	B
	C
	D
)

func getFiler(file string) filer.Filer {
	return nil
}
% time go build

real	0m1.617s
user	0m1.290s
sys	0m0.408s
% time stringer -type Type

real	0m4.197s
user	0m2.409s
sys	0m0.782s
%

Stringer is taking almost 3 times as long to run as it takes to compile and link the binary. That’s crazy. If we remove the dependency on filer, which has a pretty big set of dependencies itself, stringer runs quickly again.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 3
  • Comments: 28 (21 by maintainers)

Commits related to this issue

Most upvoted comments

Hoping to send out working code today. It’s been a fractal of details.

@cznic https://go-review.googlesource.com/c/tools/+/116359, though there isn’t any published code yet.

I still get this bug when I use “gc”:

stringer: checking package: x.go:4:2: could not import gopkg.in/src-d/go-license-detector.v2/licensedb/filer (can’t find import: “gopkg.in/src-d/go-license-detector.v2/licensedb/filer”)

but not when I use “source”. What is my mistake? It’s confusing.

Stringer should not care that the package compiles, only that the file parses, but changes people keep making to how things work are breaking all such assumptions.