Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: Standard library gets cached in GOCACHE folder via 'go build/install std' and the cache expires with time #65204

Closed
maxkt opened this issue Jan 22, 2024 · 1 comment
Labels
Milestone

Comments

@maxkt
Copy link

maxkt commented Jan 22, 2024

Go version

go version go1.21.6 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/var/tmp/go/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go-1.21'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go-1.21/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.6'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1420125502=/tmp/go-build -gno-record-gcc-switches'

What did you do?

My application executes a lot of small Go scripts programmatically. These scripts reference the standard library.

My goal is to precompile the standard library (std) so that it is never compiled again until I update the Go version. That would help me speed up the small scripts execution.

However when I do go install std or go build std, the compilation results are placed into GOCACHE folder. So essentially, the std gets cached rather then precompiled. And with time this cache expires and I have to run go install std again.

I believe it should be possible to precompile the std library in Go as in all other compiled languages that I'm familiar with. However I failed to find a way to do it in the documentation, github issues or SO threads. Please, help me to see what I'm missing here.

What did you see happen?

  1. Std library is cached in GOCACHE folder, and this cache expires with time even if Go version remains the same.

What did you expect to see?

Std library is precompiled and saved in GOPATH/pkg or elsewhere, where it won't be compiled ever again until I update the Go version.

@bcmills bcmills added the GoCommand cmd/go label Jan 22, 2024
@bcmills bcmills added this to the Unplanned milestone Jan 22, 2024
@bcmills
Copy link
Contributor

bcmills commented Jan 22, 2024

The standard library was intentionally moved to the cache in order to reduce distribution size (see #47257), but note that even before then the object files in the cache were sometimes not used (for example, due to the use of different build flags that affect the compiled code).

Also note that any standard-library packages you actually use should have their access times updated (and should therefore not be remove from the cache when it is trimmed).

At any rate: you can get the old behavior by setting GODEBUG=installgoroot=all in your environment.

@bcmills bcmills closed this as not planned Won't fix, can't repro, duplicate, stale Jan 22, 2024
@bcmills bcmills changed the title Standard library gets cached in GOCACHE folder via 'go build/install std' and the cache expires with time cmd/go: Standard library gets cached in GOCACHE folder via 'go build/install std' and the cache expires with time Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants