]> Cypherpunks repositories - gostls13.git/commit
cmd/go: avoid rebuilding itself in TestMain
authorDaniel Martí <mvdan@mvdan.cc>
Thu, 13 Jan 2022 12:46:34 +0000 (12:46 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 4 Mar 2022 18:03:16 +0000 (18:03 +0000)
commitca384f76296af68b874cf9305a78ca5269c20956
tree0bacbb32391db216399b721dd114aacc75d9550e
parent46afa893ebf85e23dd820a11e6007a9adb503419
cmd/go: avoid rebuilding itself in TestMain

An extra "go build" was happening, for the sake of -tags=testgo,
which would insert some extra behavior into ./internal/work.

Instead, reuse the test binary as cmd/go directly,
by calling the main func when a special env var is set.
We still duplicate the test binary into testBin,
because we need a "go" executable in that directory for $PATH.

Finally, the special behavior is instead inserted via TestMain.

The numbers below represent how long it takes to run zero tests,
measured via:

benchcmd GoTestNothing go test -run=-

That is, the time it takes to run the first test is reduced by half.
Note that these numbers are on a warm build cache,
so if the -tags=testgo build were to be done from scratch,
the speed-up would be significantly more noticeable.

name           old time/op         new time/op         delta
GoTestNothing          830ms ± 2%          380ms ± 7%  -54.23%  (p=0.008 n=5+5)

name           old user-time/op    new user-time/op    delta
GoTestNothing          1.64s ± 1%          0.82s ± 3%  -50.24%  (p=0.008 n=5+5)

name           old sys-time/op     new sys-time/op     delta
GoTestNothing          306ms ± 7%          159ms ±28%  -48.15%  (p=0.008 n=5+5)

name           old peak-RSS-bytes  new peak-RSS-bytes  delta
GoTestNothing          173MB ± 1%          147MB ± 1%  -14.96%  (p=0.008 n=5+5)

Change-Id: I1f8fc71269a7b45bc5b82b7228e13f56589d44c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/378294
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/cmd/go/export_test.go [new file with mode: 0644]
src/cmd/go/go_test.go
src/cmd/go/internal/work/build.go
src/cmd/go/internal/work/exec.go
src/cmd/go/internal/work/gc.go
src/cmd/go/internal/work/testgo.go [deleted file]
src/cmd/go/script_test.go