3

Go 1.5 managed to release a bootstrapped compiler written in Go. Assuming Go is slower than C, and the earlier Go compiler is written in C, is the bootstrapped compiler going to be slower in compilation time?

twotwotwo
  • 28,310
  • 8
  • 69
  • 56
user607722
  • 1,614
  • 2
  • 12
  • 19
  • 2
    Bootstrapping has nothing to do with it. 'Bootstrapped compiler' and 'compiler written in C' are not mutually exclusive. What you are really asking is between 'compiler written in Go' and 'compiler written in C'. – user207421 Aug 20 '15 at 22:14
  • 1
    Title didn't convey the specifics in the question body (is *Go 1.5's* bootstrapped compiler slower than *1.4's* compiler in C), so I edited it to be clearer, but it seems like a reasonable question, even if we don't entirely love the answer (yes, builds in 1.5 are slower). – twotwotwo Aug 21 '15 at 00:07

2 Answers2

7

Yes, the Go 1.5 compiler is slower, as discussed in the release notes:

Builds in Go 1.5 will be slower by a factor of about two. The automatic translation of the compiler and linker from C to Go resulted in unidiomatic Go code that performs poorly compared to well-written Go. Analysis tools and refactoring helped to improve the code, but much remains to be done. Further profiling and optimization will continue in Go 1.6 and future releases. For more details, see these slides and associated video.

Again, the compiler was (initially) automatically translated, so after the translation it output the same code as before: your programs aren't slower because the compiler is. The rest of the release notes and the links above shed more light. There are considerations other than compile speeds involved: the authors intend to move faster in Go than they could in C.

I'd recommend upgrading: open-source code will come to depend on 1.5, and if you stay behind you lose a lot of cool stuff, like big reductions in GC latency from pushing most of that work into the background (also discussed in the Performance section linked above; I wrote a bit more about it responding to another question).

You should, as with any big upgrade, test to make sure that stuff like the new default of using all available cores, tweaks to scheduling, or any of the little library behavior changes don't bite you.

twotwotwo
  • 28,310
  • 8
  • 69
  • 56
0

Well, PyPy is written in Python and it is known to be faster (sometimes) than CPython written in C.

In the case of Go, the language makes it easier to write more efficient code, so it should not be slower than the older C version. The writers were careful to make sure of this. Rather than faster it is easier to maintain and extend.

C is fast because it is close to the CPU, but the speed of a language is mostly more about the algorithms to produce the more 'advanced' feature (simple to use but advanced compared to CPU features).

A classic example is memory management. The C malloc/free is inherently slow as it reorganises free memory whenever you release it. A garbage collector sounds a lot slower because of the work it needs to do, but your program can release memory and continue on at full speed.

Paul Marrington
  • 557
  • 2
  • 7
  • Unfortunately, I don't think this is quite right--Go 1.5 compilation is slower than 1.4 (still quick compared to a lot of things, but that wasn't the question). The Go authors are hopeful they can make up some of that difference over time through performance tuning and better parallelization. Sorry not to have great cites for this, but, e.g., there's this thread starting July 5: https://groups.google.com/forum/#!topic/golang-nuts/uBFzGIturOA – twotwotwo Aug 20 '15 at 23:14
  • I also can only go on what I heard on a podcast with one of the go team. I would expect the compiler to be slower because it can now do more. Are the compiled applications slower also? – Paul Marrington Aug 20 '15 at 23:30
  • No, the speed of the code it generates is independent of the speed of the compiler in this case. Programs that had long GC pauses generally have almost all of that work pushed into the background now (I [answered about this elsewhere](https://stackoverflow.com/questions/31684862/how-fast-is-the-go-1-5-gc-with-terabytes-of-ram/31686469)). If you have tons of goroutines and context switches the scheduler changes may help you. [Otherwise many programs might see smallish changes](http://kokizzu.blogspot.com/2015/07/go-142-vs-15-beta-1-benchmark.html). – twotwotwo Aug 20 '15 at 23:50