Closed groob closed 5 years ago
cc @bcmills
On my phone, but I wonder whether adding/modifying ldflags causes cmd/go to recompile as well as re-link.
It doesn't look like it recompiles, it's the linker step that gets slower. I'm a novice when it comes to the low level things but it looks like things only slow down during the link step.
@ianlancetaylor
@groob is the slowness still present in 1.10? Did 1.11 get slower for you? Thanks.
@cherrymui
I couldn't reproduce this: (t2.go is your example with cloud.google.com/go/storage)
$ time go build -ldflags="-w" t2.go
real 0m0.844s
user 0m1.015s
sys 0m0.249s
$ time go build -ldflags="-w -X main.id=aaa" t2.go
real 0m0.854s
user 0m1.023s
sys 0m0.256s
$ time go build -ldflags="-w -X main.id=bbb" t2.go
real 0m0.849s
user 0m1.002s
sys 0m0.248s
$ time go build -ldflags="-w -X main.id=ccc" t2.go
real 0m0.833s
user 0m1.056s
sys 0m0.195s
There is no significant time change with or without -X.
I suspect that in your timing, without -X the "go" command just picks the result from the build cache, whereas with -X (especially with different value each time), it actually runs the linker. Could you use go build -x
to show what it actually does? i.e. comparing go build -x -ldflags=-w
vs. go build -x -ldflags="-w -X main.id=xxx"
. Thanks.
@cherrymui to see the difference build t2.go twice without -X. or with X but with main.id=aaa
.
My point in the initial request is that the time when main.id
is static is low/using some cache, but when main.id is dynamic (like a uuidgen output) the build time is higher.
See 1st, vs follow up builds:
bash-3.2$ time go build -ldflags "-w -X main.id=aaa"
real 0m0.862s
user 0m0.330s
sys 0m0.388s
bash-3.2$ time go build -ldflags "-w -X main.id=aaa"
real 0m0.258s
user 0m0.297s
sys 0m0.208s
bash-3.2$ time go build -ldflags "-w -X main.id=aaa"
real 0m0.266s
user 0m0.296s
sys 0m0.217s
bash-3.2$ time go build -ldflags "-w -X main.id=aaa"
real 0m0.255s
user 0m0.294s
sys 0m0.226s
And first vs followup when id changes.
bash-3.2$ time go build -ldflags "-w -X main.id=aaa"
real 0m0.261s
user 0m0.294s
sys 0m0.221s
bash-3.2$ time go build -ldflags "-w -X main.id=bbb"
real 0m1.170s
user 0m0.970s
sys 0m0.422s
Please show us the go build -x
output. That is, add -x
to your command lines. Thanks.
sure.
go build -x -ldflags "-w -X main.id=aaa"
OutputWORK=/var/folders/0y/d72wwlss7jg1gcrczzl050qr0000gn/T/go-build457697903
go build -x -ldflags "-w -X main.id=ccc"
OutputWORK=/var/folders/0y/d72wwlss7jg1gcrczzl050qr0000gn/T/go-build756309566 mkdir -p $WORK/b001/ cat >$WORK/b001/importcfg.link << 'EOF' # internal packagefile github.com/groob/linkflags=/Users/victor/Library/Caches/go-build/29/29c3b87d3e8f1025ab4f70ef57b739f7be09ac32e04d814b9ec3919979cb86e1-d packagefile cloud.google.com/go/storage=/Users/victor/Library/Caches/go-build/93/93d1895fdfda52e82712ea676a2c633cb094e98f18c3118ee929bf27673d6c77-d packagefile fmt=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/fmt.a packagefile runtime=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/runtime.a packagefile bytes=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/bytes.a packagefile cloud.google.com/go/iam=/Users/victor/Library/Caches/go-build/3d/3d069e94a50280030aa66f9be6a19f97a958d6fbcd24fa93b25e2e1128ad3f9d-d packagefile cloud.google.com/go/internal=/Users/victor/Library/Caches/go-build/03/038ad647ac7c36c6635ac7d3dab47088bb7489fff57600d1a88f068ffa52ae98-d packagefile cloud.google.com/go/internal/optional=/Users/victor/Library/Caches/go-build/e8/e8e57828fbee8caa9ea6fdd1fc65c40db75eb8047e0d8740da22fc66458082f0-d packagefile cloud.google.com/go/internal/trace=/Users/victor/Library/Caches/go-build/eb/eb9c598a3d7d1cbdebd1e0297bdb385dc0e6faf8284ea8de505d999b9d0ed2e2-d packagefile cloud.google.com/go/internal/version=/Users/victor/Library/Caches/go-build/f5/f57a73130f7f4d6af4d7efe301907581fdf6168d97370627477e0198a521333b-d packagefile context=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/context.a packagefile crypto=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto.a packagefile crypto/rand=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/rand.a packagefile crypto/rsa=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/rsa.a packagefile crypto/sha256=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/sha256.a packagefile crypto/x509=/Users/victor/Library/Caches/go-build/77/776f6d514e594409b35d70ec9b8feb089611fb702e120977e8868bcfe73674a4-d packagefile encoding/base64=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/encoding/base64.a packagefile encoding/pem=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/encoding/pem.a packagefile errors=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/errors.a packagefile github.com/googleapis/gax-go=/Users/victor/Library/Caches/go-build/50/506bd288763a3d43aea8f003d932e4638adac4392d6027163fb8547ecb9716b5-d packagefile google.golang.org/api/googleapi=/Users/victor/Library/Caches/go-build/ce/ce274a220dac6fae6fff3dfd122ed6753302dc0bf00d520e7aca48cd8db76935-d packagefile google.golang.org/api/iterator=/Users/victor/Library/Caches/go-build/0a/0a774eb26526ae21f4b90224afc523d76c3599982b9eaaa09033391601aa02d6-d packagefile google.golang.org/api/option=/Users/victor/Library/Caches/go-build/30/3034a6dd4ef4ef4e596ac7dbaf8041f5ece2f87e1c4543b783832aa30fbc2b4c-d packagefile google.golang.org/api/storage/v1=/Users/victor/Library/Caches/go-build/d1/d10b2c820304579f98bb4b046022b51d0d38dc3f5700532902fb1f9954044167-d packagefile google.golang.org/api/transport/http=/Users/victor/Library/Caches/go-build/f8/f890b8d0c38676d9b0e281f39dd20418aaa6eb8ed2a995c57655cb2b3894b851-d packagefile google.golang.org/genproto/googleapis/iam/v1=/Users/victor/Library/Caches/go-build/9c/9c3e80b511c3ffce0b7359705a9064e8d3da09b4de6e136a6e50398f857bfc39-d packagefile hash/crc32=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/hash/crc32.a packagefile io=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/io.a packagefile io/ioutil=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/io/ioutil.a packagefile net/http=/Users/victor/Library/Caches/go-build/05/05c9ce15ed4846f9c95bea02de06de249f9310849b3951c1e19bb2a6cc564aa9-d packagefile net/url=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/net/url.a packagefile reflect=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/reflect.a packagefile regexp=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/regexp.a packagefile sort=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/sort.a packagefile strconv=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/strconv.a packagefile strings=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/strings.a packagefile sync=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/sync.a packagefile time=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/time.a packagefile unicode/utf8=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/unicode/utf8.a packagefile math=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/math.a packagefile os=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/os.a packagefile internal/bytealg=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/internal/bytealg.a packagefile internal/cpu=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/internal/cpu.a packagefile runtime/internal/atomic=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/runtime/internal/atomic.a packagefile runtime/internal/sys=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/runtime/internal/sys.a packagefile unicode=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/unicode.a packagefile google.golang.org/grpc=/Users/victor/Library/Caches/go-build/3d/3df61ad99dd071690917ec1effe14addcdf4671bb2522cd6bf22ec73b9bd0c26-d packagefile google.golang.org/grpc/codes=/Users/victor/Library/Caches/go-build/8f/8f7c19ec1319f9831b45a0335b2396e07b04f34b4f01f0f99a9a37fc7e5a992a-d packagefile google.golang.org/grpc/status=/Users/victor/Library/Caches/go-build/51/514ede385c3efd1595e0af28905339d8c123fffc0b318d678315e7d57e3d9066-d packagefile go.opencensus.io/trace=/Users/victor/Library/Caches/go-build/f7/f7507b23c0adcdc5a7138026b236f044368b40277cad0056d253d1cf21195d3b-d packagefile google.golang.org/genproto/googleapis/rpc/code=/Users/victor/Library/Caches/go-build/d6/d69cde84c4221213899f4cfc8d51ca981f94efab90e8754b2a8927e2b7d14ba5-d packagefile hash=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/hash.a packagefile bufio=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/bufio.a packagefile crypto/aes=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/aes.a packagefile crypto/cipher=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/cipher.a packagefile math/big=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/math/big.a packagefile syscall=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/syscall.a packagefile crypto/internal/randutil=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/internal/randutil.a packagefile crypto/subtle=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/subtle.a packagefile crypto/des=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/des.a packagefile crypto/dsa=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/dsa.a packagefile crypto/ecdsa=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/ecdsa.a packagefile crypto/elliptic=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/elliptic.a packagefile crypto/md5=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/md5.a packagefile crypto/sha1=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/sha1.a packagefile crypto/sha512=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/sha512.a packagefile crypto/x509/pkix=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/x509/pkix.a packagefile encoding/asn1=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/encoding/asn1.a packagefile encoding/hex=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/encoding/hex.a packagefile vendor/golang_org/x/crypto/cryptobyte=/Users/victor/Library/Caches/go-build/11/111718e0574031ff4ae165673b76d1eed9539939f9227d637cc2016ded48bc8e-d packagefile vendor/golang_org/x/crypto/cryptobyte/asn1=/Users/victor/Library/Caches/go-build/78/78d8397c53324794f3b5d977370d5920559cd035afe81222316558b98ff6b521-d packagefile net=/Users/victor/Library/Caches/go-build/63/63faa2d0048f15077d355a7e1e56fb0def75ec754f5d31695c1da05003b989cf-d packagefile os/exec=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/os/exec.a packagefile os/user=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/os/user.a packagefile path/filepath=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/path/filepath.a packagefile runtime/cgo=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/runtime/cgo.a packagefile encoding/binary=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/encoding/binary.a packagefile golang.org/x/net/context=/Users/victor/Library/Caches/go-build/13/1352e428356f040fac5c1f5b8e9035516f97c897dcc91145d0cd20b839738e8c-d packagefile math/rand=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/math/rand.a packagefile encoding/json=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/encoding/json.a packagefile google.golang.org/api/googleapi/internal/uritemplates=/Users/victor/Library/Caches/go-build/6c/6cd348fe82fb60f59fe53009286fed584184dea74ddeb800b3743d06db6b940c-d packagefile golang.org/x/oauth2=/Users/victor/Library/Caches/go-build/16/16a7e4beee177e085ad80a5eefe51dd22d5b6396abc72c785f303e453808d0f5-d packagefile golang.org/x/oauth2/google=/Users/victor/Library/Caches/go-build/55/55bc7e2c278d2b28c88725832deaa2f21d1796d4f296fd9ad61040b8eb4783ef-d packagefile google.golang.org/api/internal=/Users/victor/Library/Caches/go-build/ae/ae1d1704c5d1c4edb0ddeaf4f2e9cc7f991eebf28746da1ed0e691166cc51679-d packagefile golang.org/x/net/context/ctxhttp=/Users/victor/Library/Caches/go-build/9b/9b81c17e16a93972e3ffadd1ddda336826805e865b65c359847daf859bc22f85-d packagefile google.golang.org/api/gensupport=/Users/victor/Library/Caches/go-build/10/10eee94bf4da6ea89c55db5d6c1047baf3b76135051704fe54a0ac782f0c2b8b-d packagefile go.opencensus.io/exporter/stackdriver/propagation=/Users/victor/Library/Caches/go-build/14/14e70c387a747d5e8abb1f99cb29a91bacb9c9ef71040b8deecb64c78e6def91-d packagefile go.opencensus.io/plugin/ochttp=/Users/victor/Library/Caches/go-build/92/928cc4cf581609688ff509d6f4f87c53467825ad5c94c9cb40f7c1b923dda21a-d packagefile google.golang.org/api/googleapi/transport=/Users/victor/Library/Caches/go-build/fe/fef7952b097a0b3d7c347359609223f1d94ffea072b875bfa8ea07ea25601b90-d packagefile github.com/golang/protobuf/proto=/Users/victor/Library/Caches/go-build/d7/d7040d96e3824b91f9ddca7822f20c60be4a4dd92523033d0298850d81899402-d packagefile google.golang.org/genproto/googleapis/api/annotations=/Users/victor/Library/Caches/go-build/23/23128ed83205e76bc5cb9815b4b95048c7afcc51627f2dde78999868f1c62d98-d packagefile sync/atomic=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/sync/atomic.a packagefile compress/gzip=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/compress/gzip.a packagefile container/list=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/container/list.a packagefile crypto/tls=/Users/victor/Library/Caches/go-build/03/039e2c9026cef0f6796b21aabb8421ffa1ca9678264fca3393864f3fefbe0460-d packagefile vendor/golang_org/x/net/http/httpguts=/Users/victor/Library/Caches/go-build/47/4798fbb3c9235a0e5751a6ac372c1647f9d600890ac8808e6fa190543a01c26f-d packagefile vendor/golang_org/x/net/http/httpproxy=/Users/victor/Library/Caches/go-build/78/78ce5ed1a9abbed4909ff6cc6a5b17fc1471ebd34a938249f53878214991a6fe-d packagefile vendor/golang_org/x/net/http2/hpack=/Users/victor/Library/Caches/go-build/27/274760bd41e04e0e0809728d8c691d551a15b8339ebaa230da9cb9cdede9bfe9-d packagefile vendor/golang_org/x/net/idna=/Users/victor/Library/Caches/go-build/6a/6a45ac43ed7d3ac99fb5509b59c04b9720938d4e86dc8d20be6ec255b7231d0c-d packagefile log=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/log.a packagefile mime=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/mime.a packagefile mime/multipart=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/mime/multipart.a packagefile net/http/httptrace=/Users/victor/Library/Caches/go-build/86/86dea285c7984879b38b577aa19b848ac7f4538b1660ba5d52192a9ed1ec4441-d packagefile net/http/internal=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/net/http/internal.a packagefile net/textproto=/Users/victor/Library/Caches/go-build/d0/d0018b6f86e3997a0c9a5abbe90c7c33e954d5218abdad8ee2ca4eedaa9ef894-d packagefile path=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/path.a packagefile regexp/syntax=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/regexp/syntax.a packagefile math/bits=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/math/bits.a packagefile internal/race=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/internal/race.a packagefile internal/poll=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/internal/poll.a packagefile internal/syscall/unix=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/internal/syscall/unix.a packagefile internal/testlog=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/internal/testlog.a packagefile golang.org/x/net/http2=/Users/victor/Library/Caches/go-build/ab/ab9ba6679102e3c05359074d01519dedaca1b63ecb8bdb66a2cb55c7bc4e17fc-d packagefile golang.org/x/net/trace=/Users/victor/Library/Caches/go-build/e6/e606bb77e91d54e9c4b7ed4feb62c6669e5ca6770063dc24b0b145a68cfafa11-d packagefile google.golang.org/grpc/balancer=/Users/victor/Library/Caches/go-build/d9/d972532faf62492694021ebd874b7cea2638c73179546097b1e6fc298220def9-d packagefile google.golang.org/grpc/balancer/roundrobin=/Users/victor/Library/Caches/go-build/14/14aa0bf1bd850902492b2e1deac96b827c8263426ff3be953fa33e2a40211075-d packagefile google.golang.org/grpc/channelz=/Users/victor/Library/Caches/go-build/68/6856567f5c086f822ecde633c993a5bd4dd2eb4cfbf9cabb76c2b14970c1eec1-d packagefile google.golang.org/grpc/connectivity=/Users/victor/Library/Caches/go-build/34/34b3f3c0ddbedbeef3b75bccefad9935953d6161063f5106e6b34d0d9d35041c-d packagefile google.golang.org/grpc/credentials=/Users/victor/Library/Caches/go-build/bc/bcde9e7652e29d9eb951d1870a720d582dd3e547a3eeadebc4285875cc8b6cc8-d packagefile google.golang.org/grpc/encoding=/Users/victor/Library/Caches/go-build/60/604d8901310fe2bf420475bf9429d1a019188280dc19b3d939dec703af289800-d packagefile google.golang.org/grpc/encoding/proto=/Users/victor/Library/Caches/go-build/ab/abe822296f9f19524e7adf1cb2e0d719eadaed2f3db3363c3110776416b5084e-d packagefile google.golang.org/grpc/grpclb/grpc_lb_v1/messages=/Users/victor/Library/Caches/go-build/80/8086f1ef230a82a1268c7dd7280460147ea2e187b95c640d7cb9a8081e12dee0-d packagefile google.golang.org/grpc/grpclog=/Users/victor/Library/Caches/go-build/ce/ce7aa8f40326968ebde4d3ec864c55ca13a42e3405f6e7a91668ee9761fe782e-d packagefile google.golang.org/grpc/internal=/Users/victor/Library/Caches/go-build/b4/b47b3e4648e048d867079cd3075b75a74bbbbe1aacdb5a2a9b85c9cf79b0d5cf-d packagefile google.golang.org/grpc/internal/grpcrand=/Users/victor/Library/Caches/go-build/ef/efff67a95e0d97695a4c0d3918017cee0cb6a1eb9e1907e1074505153fab1ee4-d packagefile google.golang.org/grpc/keepalive=/Users/victor/Library/Caches/go-build/c9/c9f3d866a29a6e2d2368ed94c21b6456c2b2cda2e9f4afc3f2c07f3c7c738331-d packagefile google.golang.org/grpc/metadata=/Users/victor/Library/Caches/go-build/63/63ae7b1b2658f63b6ecc5f2cbded44eebf64a554cdae1abd60cfc1a405f856ab-d packagefile google.golang.org/grpc/naming=/Users/victor/Library/Caches/go-build/9d/9dd64269d8f62ace861da27697a42dadfbbc362a942be094f36b8a01f4d56893-d packagefile google.golang.org/grpc/peer=/Users/victor/Library/Caches/go-build/63/63faf87cf6847d9755539770fd860e35d41a253ef5648ca7e8f562d6c13012c0-d packagefile google.golang.org/grpc/resolver=/Users/victor/Library/Caches/go-build/8c/8ca646a70a0fdaec231cd848481f2637b5e056f81b78f961a3388235c2d96c05-d packagefile google.golang.org/grpc/resolver/dns=/Users/victor/Library/Caches/go-build/bc/bc20f395aa6f642da60846beed40f341ec7ac1d9dc147b8299f116cb25feb34a-d packagefile google.golang.org/grpc/resolver/passthrough=/Users/victor/Library/Caches/go-build/a3/a348a862d71beecd8cb47bd9134662e2bdf54194d95c5728f40bfbd5df5a0099-d packagefile google.golang.org/grpc/stats=/Users/victor/Library/Caches/go-build/d4/d4778c25bc3afa03dac4095e8101821959aecdf2722a0c52e71a4c3355dfdffe-d packagefile google.golang.org/grpc/tap=/Users/victor/Library/Caches/go-build/f2/f21d3df04f331512300a9427a9a93d89f71b31caea137b82a928bcfd790083c8-d packagefile google.golang.org/grpc/transport=/Users/victor/Library/Caches/go-build/21/213d55c572db001b883fb6371577dadcc40cf03fa5f8627c3fcb0b41c83494b4-d packagefile net/http/httputil=/Users/victor/Library/Caches/go-build/f1/f1ce372521237ebc3ce8dc8435f1f9558541d100066dba1c20bf75816ee76630-d packagefile github.com/golang/protobuf/ptypes=/Users/victor/Library/Caches/go-build/ed/ed1219ac8ea91da03179eff7bc3ed84cfc756020be0aa17f4caee9f40e9a700f-d packagefile google.golang.org/genproto/googleapis/rpc/status=/Users/victor/Library/Caches/go-build/ea/eae96465e23cccc2dcc491a2443ba2c49c3ab502b1eaaa00a9705f8c4ba75e49-d packagefile go.opencensus.io/internal=/Users/victor/Library/Caches/go-build/ea/ea523db62cd282f4b63ad86e25986dd4b443e0aaf1f97eb17883d787c129543d-d packagefile go.opencensus.io/trace/internal=/Users/victor/Library/Caches/go-build/47/4783ff3bb015a5d52e22df7249580b9609860a50fc567473e0d5efc15a0bd3fd-d packagefile runtime/trace=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/runtime/trace.a packagefile crypto/internal/subtle=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/internal/subtle.a packagefile vendor/golang_org/x/net/dns/dnsmessage=/Users/victor/Library/Caches/go-build/e3/e31d3d09964c8e383ea1bbfad13caedaafe9152c749153724bc9d3fddf905500-d packagefile vendor/golang_org/x/net/route=/Users/victor/Library/Caches/go-build/dd/dd6cddcfbadb21b4b5167f1f712d8d5b4f3cdb7f2c46111836c3035ac8a79c9b-d packagefile internal/nettrace=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/internal/nettrace.a packagefile internal/singleflight=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/internal/singleflight.a packagefile encoding=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/encoding.a packagefile unicode/utf16=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/unicode/utf16.a packagefile golang.org/x/oauth2/internal=/Users/victor/Library/Caches/go-build/ac/ac8b5834597b3e26fe377057f59cd02f88177d4d388c81a0ac5155cfe729d241-d packagefile cloud.google.com/go/compute/metadata=/Users/victor/Library/Caches/go-build/00/008cabc9b65f39cf09894cc016debd54f8e28aef21e13aedf3fdcbcdf1ae5f7f-d packagefile golang.org/x/oauth2/jws=/Users/victor/Library/Caches/go-build/5e/5ebcf26d91d8b3f6b97834fade0e9e5671fee26418713d965e87641eecc4303f-d packagefile golang.org/x/oauth2/jwt=/Users/victor/Library/Caches/go-build/18/18c9de4b0f7b42c926be0cffe7e0d542eaa90deec6965c7d82e7bdaa20823611-d packagefile go.opencensus.io/trace/propagation=/Users/victor/Library/Caches/go-build/5b/5b54745ec0a112a22f5e0b003f2d16daf6ff865b58a50603e248bfac38448ed6-d packagefile go.opencensus.io/plugin/ochttp/propagation/b3=/Users/victor/Library/Caches/go-build/47/4785d7c1e98cdd36c8ae7d584e880d6a783d286f866a765df2f4b06cd33d8a19-d packagefile go.opencensus.io/stats=/Users/victor/Library/Caches/go-build/ad/ada52ffef5bad61c18f7b73d47ad09446e31d4e024205063cb26af021c55b4a4-d packagefile go.opencensus.io/stats/view=/Users/victor/Library/Caches/go-build/34/34a841bcfea231d05c20e2d013c0e6d3c70987dd5565afd7224ea599942e81f4-d packagefile go.opencensus.io/tag=/Users/victor/Library/Caches/go-build/38/382f0b14f77de0bb11aef05006001538a45c792c9845121680c454c1c46bc975-d packagefile github.com/golang/protobuf/protoc-gen-go/descriptor=/Users/victor/Library/Caches/go-build/5e/5e13c2f999dd8f199ddf6fdd42befecebf0fe5806aa986dc6a5421588de01506-d packagefile compress/flate=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/compress/flate.a packagefile crypto/hmac=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/hmac.a packagefile crypto/rc4=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/crypto/rc4.a packagefile vendor/golang_org/x/crypto/chacha20poly1305=/Users/victor/Library/Caches/go-build/6c/6cb6961b48724d1946f74efd43fa7ad133da9c65429c8689663fc18c1b76e78a-d packagefile vendor/golang_org/x/crypto/curve25519=/Users/victor/Library/Caches/go-build/01/01c2f3b73f2cb6a93abd6b7a0e5e5a44e9b52dbfb6200a07ef2d3f8f3daf4be4-d packagefile vendor/golang_org/x/text/secure/bidirule=/Users/victor/Library/Caches/go-build/1b/1b5541064970f57f5052427ef7b213fc29000b9d998d6f54d2d779402c276810-d packagefile vendor/golang_org/x/text/unicode/bidi=/Users/victor/Library/Caches/go-build/3f/3f72130a790b63782ade096af4131c0fa47159bd56982b4b771f5a7ae49cc173-d packagefile vendor/golang_org/x/text/unicode/norm=/Users/victor/Library/Caches/go-build/c3/c380b771fcee8cfc09070ef0f9ee08b6fc7f1e11428fa596e5f2dc73a6d06432-d packagefile mime/quotedprintable=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/mime/quotedprintable.a packagefile golang.org/x/net/http/httpguts=/Users/victor/Library/Caches/go-build/79/7907f226b7b9c89e3d817d18404ff5e063f0bc94ce0cb3518d27b0b2cd72b0c6-d packagefile golang.org/x/net/http2/hpack=/Users/victor/Library/Caches/go-build/a8/a81358298bac8b373be40ffd0490035e2cdee09895254e8e3822eccf7905f1d3-d packagefile golang.org/x/net/idna=/Users/victor/Library/Caches/go-build/21/210d037e2f6ee9ecd06a7f2608b815e7fb27f61fc586450ce017521716195265-d packagefile golang.org/x/net/internal/timeseries=/Users/victor/Library/Caches/go-build/d8/d862f344a57f1b9a8f32c46c4a7aa6ba7191116e0f24d79be962bcdb61b65a59-d packagefile html/template=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/html/template.a packagefile text/tabwriter=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/text/tabwriter.a packagefile google.golang.org/grpc/balancer/base=/Users/victor/Library/Caches/go-build/af/af7fd2ecb97b29786039c54f7e7f612777499480eb45e90c23db1a48b945d0f4-d packagefile github.com/golang/protobuf/ptypes/any=/Users/victor/Library/Caches/go-build/e2/e2e195b2a9fd7f85a0188296df691657d49d1c170b0af747531e5a80dc24b694-d packagefile github.com/golang/protobuf/ptypes/duration=/Users/victor/Library/Caches/go-build/81/81bad047c147036c40db516e08c3c7d933a0438c9f08116d5710ac3166a19078-d packagefile github.com/golang/protobuf/ptypes/timestamp=/Users/victor/Library/Caches/go-build/da/dac7888eda275b132ea40eb993ad7e598ce5a623d3e3667d7870ccb03816bd32-d packagefile go.opencensus.io/stats/internal=/Users/victor/Library/Caches/go-build/81/81075e96ee5e4959ca07b530e842bae7eaa91dd7bafab63995bc091cc4b7f23e-d packagefile go.opencensus.io/internal/tagencoding=/Users/victor/Library/Caches/go-build/7b/7b48120464c94f4cc902da55148387528ea880075b92d436bbacfbc34a2e62cc-d packagefile runtime/pprof=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/runtime/pprof.a packagefile vendor/golang_org/x/crypto/internal/chacha20=/Users/victor/Library/Caches/go-build/08/08d2b946b85f738605e511c4182a8f8d86381771890486b24fcb544897300d3c-d packagefile vendor/golang_org/x/crypto/poly1305=/Users/victor/Library/Caches/go-build/77/7733f1daba0c21a4c7b10e0bb02cf3d1ef048dd6a8e846a27ef1d85def66f032-d packagefile vendor/golang_org/x/text/transform=/Users/victor/Library/Caches/go-build/a7/a7c59e91b4f69c4ff64f7b5b10c17aff50c9580e2a897447cef5afbce9b0c4f5-d packagefile golang.org/x/text/secure/bidirule=/Users/victor/Library/Caches/go-build/4b/4b878a0ea39e003c438ec787ee1fcd88be0cd2c81d0bc820f738601058407afc-d packagefile golang.org/x/text/unicode/bidi=/Users/victor/Library/Caches/go-build/c4/c46618876fb86e31796aea7ffb118658748cb5f650131c6c5972859be0de6ace-d packagefile golang.org/x/text/unicode/norm=/Users/victor/Library/Caches/go-build/a7/a7feb9296a8fe29bb91c0316827ea7f0004a265becfc9cc21f9a91ecf4601008-d packagefile html=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/html.a packagefile text/template=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/text/template.a packagefile text/template/parse=/usr/local/Cellar/go/1.11.2/libexec/pkg/darwin_amd64/text/template/parse.a packagefile golang.org/x/text/transform=/Users/victor/Library/Caches/go-build/e8/e85d415426fd102fbdd1a1b0ea354a29d9d145614510f964a333c04a76bd38d5-d EOF mkdir -p $WORK/b001/exe/ cd . /usr/local/Cellar/go/1.11.2/libexec/pkg/tool/darwin_amd64/link -o $WORK/b001/exe/a.out -importcfg $WORK/b001/importcfg.link -buildmode=exe -buildid=WccKYuhlKGKqmepH0Amq/sWLziCmCyftgmtAsiCO5/TH0tP_eFgaUjIl190FEM/WccKYuhlKGKqmepH0Amq -w -X main.id=ccc -extld=clang /Users/victor/Library/Caches/go-build/29/29c3b87d3e8f1025ab4f70ef57b739f7be09ac32e04d814b9ec3919979cb86e1-d /usr/local/Cellar/go/1.11.2/libexec/pkg/tool/darwin_amd64/buildid -w $WORK/b001/exe/a.out # internal mv $WORK/b001/exe/a.out linkflags rm -r $WORK/b001/
Ah something interesting. After I build ccc
, the cache for aaa
is now busted so it takes a while to build again.
Thanks. The build cache does not actually cache fully linked binaries, because of their size. Instead, it computes the build ID of the link, and compares that to the build ID recorded in the binary. In your case you are using the same binary, so whether the link is fast or slow depends entirely on how the last build was run. If you consistently run go build -o aaa -ldflags="-w -X main.id=aaa"
and go build -o ccc -w -ldflags="-w -X main.id=ccc"
then I predict that the build times will be equivalent.
Is there something that can be improved here? I could remove the build date from flags, or make it less granular, but it also reduces the usefulness. Many projects (kubernetes for example) tag the build with a timestamp, it would be nice if there was some workaround for this.
I think we need to be clear on what is happening. In the fast link case, there is nothing to do. The executable is already up to date. In the slow link case, the executable is not up to date, and the linker has to be invoked. So the issue is not whether the linker runs faster or slower, it's whether the linker needs to be run at all.
If you want to build with a timestamp, then by definition if the timestamp changes then the executable is out of date, and the linker has to be run. So once you've made that decision, you have to run the linker, and you will see the build time effect of that.
So when you ask whether there is something that can be improved, the answer is: don't build with a timestamp. If you want to build with a timestamp, then you have to invoke the linker, at least within the granularity of the timestamp. That's not optional.
(One approach you could use would be to make the timestamp a separate step. Run with -X SomeStringThatNeverHappens
and then in a second step replace that string with the timestamp you want. Then the linker will not be invoked if nothing has changed, and you can set the timestamp as you please.)
(feel free to point me to Slack instead). Could you elaborate on how to go about doing what you're suggesting? How would one do this:
you can set the timestamp as you please.
I was going to work around this by having two make targets, one for building with timestamp and one without. But perhaps I'm missing a easier way.
sed -e 's/SomeStringThatNeverHappens/myFavoriteTimestamp/' < bin1 > bin2
Sounds like this is sorted out sufficiently. I'm going to close this issue; please comment if you'd like me to re-open it.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
NOTE, I'm attaching this example as a zip archive. linkflags.zip
I use
-ldflags -X build_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
during the build step to attach a build time and current version to my go program. Having a dynamic field like date in ldflags increases the build time in projects significantly.Starting with a simple main.go:
When I use a static value like =X, the first time the build is slower, but then I see faster build times.
Note: I'm using
-w
due to https://github.com/golang/go/issues/26318Now when, the ldflags value changes between builds, the time goes up:
In a real project with lots of transitive dependencies this build time is much worse. In our relatively large codebase it takes 4 seconds with ldflags, and 1 second without to create a build. Even modifying this example to introduce the GCP library as a dependency shows a significant increase.
-ldflags "-w -v="2"
OutputWhat did you expect to see?
go build
builds a go program fast.What did you see instead?
Slow
go build
times.