Makefile: cache go env values#25870
Conversation
Spawning shells is expensive for Makefile targets. We use the `OS` and `ARCH` variables in a lot of places. They come from spawning a subshell and then executing `go env GOOS` or `go env GOARCH`. So, everytime we need them, we spawn a subshells. Just parsing the Makefile adds quite some time, even if the target itself is fast. This PR caches those values, so that we only need to spawn a subshell once per execution. Tests show that running `make print-version` is now much faster: Using linux: drop from 56s to 0.240s Using MacOS M1: drop from 291ms to 119ms YMMV
9bd5868 to
d94841e
Compare
camscale
left a comment
There was a problem hiding this comment.
Really odd that you're seeing 56s to run print-version. Takes 100ms for me. But with this change it takes 25ms, so that's worth it.
Note for others reading this: ifeq ("$(ARCH)","linux") and we have a bare export directive, so it would be evaluated for export anyway. Usually a recursively expanded var is only expanded if it is referenced, so on first glance it looks like it would required go be installed regardless of target being run, but that is already the case because of the aforementioned reasons.
espadolini
left a comment
There was a problem hiding this comment.
It would be nice to figure out why the go env invocation is so much slower on Linux. @marcoandredinis, were you in docker and/or emulating x86 from arm?
|
I'm seeing a lot of calls to Compared to Mac |
I was using a linux laptop, no other layer (no docker nor using any virtualization) |
Spawning shells is expensive for Makefile targets.
We use the
OSandARCHvariables in a lot of places.They come from spawning a subshell and then executing
go env GOOSorgo env GOARCH.So, everytime we need them, we spawn a subshell.
Just parsing the Makefile adds quite some time, even if the target itself is fast.
This PR caches those values, so that we only need to spawn a subshell once per execution.
Tests show that running
make print-versionis now much faster:Using linux: drop from 56s to 0.240s
Using MacOS M1: drop from 291ms to 119ms
YMMV