What I’ve done so far:
git committ
ed thego.mod
andgo.sum
files, so those files are available- run
go get ./...
- run
go mod download
Then when I run the target file:
- run
go run script-xyz.go
- … I was expecting it to be able to run immediately, but it seems to stall for about 20-30 seconds before actually running the code it it.
- I assume therefore that it is downloading/ installing more stuff before it starts
- run
go run script-xyz.go
again- This time the script runs immediately
How to reproduce
- Here’s the repo: https://github.com/hedera-dev/hello-future-world-go
- Use the
develop
branch
- Use the
- To run it on a “clean” container: https://gitpod.io/?autostart=true&editor=code&workspaceClass=g1-standard#https://github.com/hedera-dev/hello-future-world-go/tree/develop
- Note that if you run it on your own computer, you’re only going to be able to reproduce this the very first time, hence the need for a clean instance
- Steps:
- open a new terminal tab
- run
cd transfer
- run
go run script-transfer-hbar.go
- note that the “get_deps” terminal tab is where the dependencies get installed, as this runs
util/03b-get-additional-dependencies.sh
Following up on Burak Serdar’s comment below:
I tried to explicitly time go build
, and it looks like the first time it is run, it does indeed take ~30s.
Then edit the source code slightly, so it cannot reuse the cached result, and invoke go build again
.
The second time it only takes ~3s … significantly faster.
What’s can explain this difference in the duration?
gitpod /workspace/hello-future-world-go/transfer (develop) $ time go build
real 0m37.269s
user 1m39.823s
sys 0m19.747s
Edit the source code so that it needs to build again
gitpod /workspace/hello-future-world-go/transfer (develop) $ time go build
real 0m2.595s
user 0m2.674s
sys 0m1.009s
9