Hacker News new | ask | show | jobs
by oelmekki 3506 days ago
Before golang, my experience with compilation was about building softwares as an user in gentoo, and a few LFS. Speed of compilation was the first thing that stroke me with golang. But then again, it was the first time I was actually writing code to be compiled.

Is it that usual C/C++ opensource projects are very big, or am I correct to assume golang compiler processing go code is indeed really faster than gcc processing C/C++ ?

3 comments

The 10.000 foot view is that C code is optimized more, but compiles slower.

Historically this was always seen as a good tradeoff. You only compile once, but code runs thousands of times or more. Therefore a large slowdown in compilation is seen as a good tradeoff for better runtime speed.

Go follows the turbo pascal type compilers in that

1) the language is limited in several ways to make compilation faster (e.g. it is given as an argument against generics)

2) the compiler just doesn't try a whole range of optimizations

Unfortunately this is not really what you're seeing. What you're seeing in this case is a massive difference in the size of the projects you're compiling.

Go has been written with the explicit purpose of making writing large programs somewhere between tedious and impossible. By contrast, many C/C++ programs are huge. Tens to hundreds of megabytes of source code, and when compiling Gentoo, I bet you're compiling more than a gigabyte total.

Very insightful. Thanks!
C and C++ are slow to compile due to their compilation model based on text expansion instead of actual modules.

Since the 70's that Go like compilation times are possible in module based languages.

Compiling C++ is usually pretty slow. Go and C would be significantly faster.
One of the focuses with Go's compilation design was trying to avoid all the extra work that happens in C compilation that could be avoided by some careful language design.

There's a good write up here: https://talks.golang.org/2012/splash.article, but particularly starting at point 5 on that page.