Improving Build Efficiency in Go: Cache-Based Solutions
The issue of slow build times in Go, particularly for small cgo-based programs , has prompted the Go community to explore alternative solutions. The go build and go run commands have historically been noticeably slower than expected, leading to a desire for improved caching mechanisms.
One possible solution is to utilize a Makefile with a % rule. However, as the Go language designers suggest, Go's built-in build support should eliminate the need for external tools like Makefiles.
Fortunately, a significant improvement is coming. Go 1.10, expected to be released in the first quarter of 2018, will significantly improve the build speed of go build and go install. The Go command will now maintain a cache and other small metadata of built packages, saved by default in the operating system-defined user cache directory, but can be moved by setting $GOCACHE.
The main impact of this build cache is that commands like "go test" and "go build" can run quickly and always build incrementally, reusing past build steps as aggressively as possible. This means users no longer need to use "go test -i" or "go build -i" or "go install" to get fast incremental builds.
It is worth noting that go install does not install dependencies of named packages. You can learn more about what this command does by reading "go build build what?"
The above is the detailed content of How Can Go 1.10 Improve Build Efficiency, Especially for Small cgo-Based Programs?. For more information, please follow other related articles on the PHP Chinese website!