Slower cgo compilation after go1.1?

215 views
Skip to first unread message

decitrig

unread,
May 16, 2013, 8:49:52 PM5/16/13
to golan...@googlegroups.com
I just upgraded to go1.1, and it appears that cgo compilation is dramatically slower now. Previously I hadn't noticed much difference between pure go & cgo compiles, but now its dramatically slower. For example:

package main

import (
"fmt"

)

func main() {
fmt.Println("foo")
}

compiles in 0.139s, while 

package main

import (
"fmt"

)

func main() {
fmt.Println("foo")
}

compiles in 5.234s.

I hunted through the release notes but didn't see anything that would explain the difference - is this a bug in my setup, or is it reproducible?

--
rwsims

Dave Cheney

unread,
May 16, 2013, 8:53:11 PM5/16/13
to decitrig, golang-nuts
I suggest trying two things

1. compare the output of go build -x between 1.0 and 1.1, I suspect
there are more steps

2. run each of the -x steps by hand (you can just copy and paste them)
and time them yourself

At a guess I'd say this was the extra work put into the external
linking mode of cgo that is taking the additional time.
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Vova Niki

unread,
May 16, 2013, 9:02:59 PM5/16/13
to golan...@googlegroups.com
I think you just need to "go install" the cgo package and then it will be fast again 

kane....@sendgrid.com

unread,
May 13, 2014, 7:41:47 PM5/13/14
to golan...@googlegroups.com
Did you find a solution to this issue? I also think cgo is painfully slow now.

Dave Cheney

unread,
May 14, 2014, 6:19:43 AM5/14/14
to golan...@googlegroups.com, kane....@sendgrid.com
Kane,

It is likely that your old .a files (in $GOPATH/pkg) would be considered invalid by the compiler so it will be building them again.

Two things you can do

1. go build -v $PKG will show you the package it is compiling and any dependencies you need to compile before. If that is is surprisingly long, go to step 2
2. go install -v will install newer versions of those packages and reduce the amount that needs to be recompiled every time.

In summary, -v is a useful flag, I have several aliases set up so it is automatic, ie

alias gb='go install -v'
Reply all
Reply to author
Forward
0 new messages