<p>Hey. I recently started looking at Go and I am just writing a couple of small programs to get the hang of it.</p>
<p>I just wanted to make sure that I am not compiling my Go apps in an inefficient or stupid way.</p>
<p>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.</p>
<p>Is this the right way to do it or is there a way to make the programs compile faster/safer?</p>
<hr/>**评论:**<br/><br/>dbud: <pre><p>"go install" actually installs your app to $GOPATH/bin</p>
<p>so, you don't really have any need of doing "go build".</p>
<p>Usually, I put $GOPATH/bin in my path and my "dev cycle" is.</p>
<p>go install ./... && app # where app is name of my binary.</p>
<p>then a bounce is just Ctrl-C + Up + enter
which gives me (usually) a 1 second cycle time to test changes</p></pre>DeedleFake: <pre><blockquote>
<p>"go install" actually installs your app to $GOPATH/bin </p>
</blockquote>
<p>Or <code>$GOPATH/pkg</code> if it's not <code>main</code>.</p></pre>giovannibajo: <pre><p>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.</p>
<p>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.</p>
<p>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.</p></pre>afghanPower: <pre><p>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:</p>
<pre><code> import (
"database/sql"
"log"
"strconv"
"time"
"github.com/coopernurse/gorp"
"github.com/gin-gonic/gin"
_ "github.com/mattn/go-sqlite3"
</code></pre>
<p>)</p></pre>dlsniper: <pre><p>Use go install on the go-sqlite3 package and hopefully that should improve the compile times.</p></pre>afghanPower: <pre><p>Have run the "go install #pkg_link" on all of the github packages.</p></pre>dlsniper: <pre><p>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 </p></pre>robertmeta: <pre><p>Why not just <strong>go install</strong>? </p>
<p>Isn't <strong>go build</strong> considered bad practice at this point? </p></pre>TheMerovius: <pre><p>Use <code>go build -v -i</code>, whenever something's slow. You'll figure out what is slow and it will probably not continue to be slow.</p></pre>lhxtx: <pre><p>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)</p></pre>