Compiling times

xuanbao · 2016-04-03 21:51:54 · 653 次点击    
这是一个分享于 2016-04-03 21:51:54 的资源,其中的信息可能已经有所发展或是发生改变。

Hey. I recently started looking at Go and I am just writing a couple of small programs to get the hang of it.

I just wanted to make sure that I am not compiling my Go apps in an inefficient or stupid way.

Once I figure out which packages I want to import and work with I run the "go install" command. This takes 1-2 seconds. After that I run "go build" which takes 1-2 seconds as well. Is this considered fast? I am on a i7 4600u 2.1GHz CPU with 8 GB of RAM.

Is this the right way to do it or is there a way to make the programs compile faster/safer?


评论:

dbud:

"go install" actually installs your app to $GOPATH/bin

so, you don't really have any need of doing "go build".

Usually, I put $GOPATH/bin in my path and my "dev cycle" is.

go install ./... && app # where app is name of my binary.

then a bounce is just Ctrl-C + Up + enter which gives me (usually) a 1 second cycle time to test changes

DeedleFake:

"go install" actually installs your app to $GOPATH/bin

Or $GOPATH/pkg if it's not main.

giovannibajo:

You can use "go build -v" to see which packages are being compiled and "-x" to see actual process calls in case you want to dive further.

The important part is to understand that "go build" doesn't cache compilation of packages, it just creates the final file and throw all intermediate files. So if your program is made by 3 packages, "go build" will normally recompile all three of them.

You can use "go build -i" to force Go to create .a files for dependent packages (stored in $GOPATH/pkg), so that you don't need to compile them over and over. I run "go build -i" as my standard build command.

afghanPower:

Ran "go build -i" on one of my "gin-gonic" test programs. It doesn't seem to make the compiling faster. Which is kind of weird, isn't it? You would think that not compiling these dependent packages would make the compiling faster:

  import (
"database/sql"
"log"
"strconv"
"time"
"github.com/coopernurse/gorp"
"github.com/gin-gonic/gin"
_ "github.com/mattn/go-sqlite3"

)

dlsniper:

Use go install on the go-sqlite3 package and hopefully that should improve the compile times.

afghanPower:

Have run the "go install #pkg_link" on all of the github packages.

dlsniper:

Oh, I see. You are importing the package_ Try to separate that logic into a separate package and then go install that package. Overall compile times should improve at the cost of having to install that package when you change it

robertmeta:

Why not just go install?

Isn't go build considered bad practice at this point?

TheMerovius:

Use go build -v -i, whenever something's slow. You'll figure out what is slow and it will probably not continue to be slow.

lhxtx:

No need to run go build after go install. Go build just builds the binary in the packages directory. Go install builds the binary and puts it in $GOPATH/bin (which would be on your system's path, so you can call it anywhere)


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

653 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传