]> Cypherpunks repositories - gostls13.git/commit
cmd/go: cache compiler flag info
authorRuss Cox <rsc@golang.org>
Fri, 11 Feb 2022 22:17:54 +0000 (17:17 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 10 Nov 2022 04:09:44 +0000 (04:09 +0000)
commitdb259cdd80eff527e8f344d678031c516167d258
tree2a38ed74813d25a4b8a0da7e51e8d7b43646cce0
parentcb6e4f08c2e760c4eb90f3ed50eca3177b7ff6ff
cmd/go: cache compiler flag info

When you run 'go env' or any command that needs to consider
what the default gcc flags are (such as 'go list net' or
'go list <any package with net as a dependency>'),
the go command runs gcc (or clang) a few times to see what
flags are available.

These runs can be quite expensive on some systems, particularly
Macs that seem to need to occasionally cache something before
gcc/clang can execute quickly.

To fix this, cache the derived information about gcc under a cache
key derived from the size and modification time of the compiler binary.
This is not foolproof, but it should be good enough.

% go install cmd/go
% time go env >/dev/null
        0.22 real         0.01 user         0.01 sys
% time go env >/dev/null
        0.03 real         0.01 user         0.01 sys
%

Fixes #50982.

Change-Id: Iba7955dd10f610f2793e1accbd2d06922f928faa
Reviewed-on: https://go-review.googlesource.com/c/go/+/392454
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
src/cmd/go/internal/envcmd/env.go
src/cmd/go/internal/work/action.go
src/cmd/go/internal/work/buildid.go
src/cmd/go/internal/work/exec.go
src/cmd/go/testdata/script/env_cache.txt [new file with mode: 0644]