DEV Community

Cover image for Why are C and C++ slow to build?
Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on

Why are C and C++ slow to build?

Originally asked in Quora.

Rather, compared to Golang, why is pure Golang fast to build (in the matter of seconds), despite compiled?

Actually, any libraries in any languages (e.g. Python, Node.js, R, LaTeX, even Golang), that involves binding for C or C++, can be excruciating slow to compile, if not bundled with binary or precompiled. (I have seen an R library built in 20 minutes. Also, ConTeXt is very slow to build.)

go-sqlite3 when changing tags or CGO_CFLAGS even a little bit, will be slow to compile (in a matter of a few minutes).

And, not only C and C++. Java and Scala, amongst compiled languages, can be very slow to compiled as well.

Top comments (3)

Collapse
 
atom3333 profile image
Thomas Ferrand

During the design of the Go language it has been a conscious decision to ensure compilation would be small.
The biggest problem wrt compilation time in C and C++ is the archaic dependency management system, text source inclusion which means that a lot of work have to be performed for each translation unit even if it has already been done in another.
Additionally, C++ library tend be template-heavy and template instantiation is a lot of work for the C++ compiler.
Finally, when dealing with with optimized builds, C and C++ compiler apply more optimizations (which makes the compilation slower) whereas the Go compiler only apply a subset of the optimizations.
For more details look at this stackoverflow.com/questions/297663...

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

WoW, perfect SO discussion.

Makes me think, why can't a language have both development compilation (i.e. fast, therefore, faster dev cycle, but not sacrificing developer's experience); and slow compilation (i.e. highly optimized)?

I realized that there might be multiple languages tried after C, but before Go; but for some reasons, Go is quite successful.

Collapse
 
atom3333 profile image
Thomas Ferrand • Edited

Makes me think, why can't a language have both development compilation (i.e. fast, therefore, faster dev cycle, but not sacrificing developer's experience); and slow compilation (i.e. highly optimized)?

I don't think there is a reason it wouldn't be possible, it just need to be done and might have already been. I haven't tried newer language like rust, zig and the like yet so maybe one of them offer this and I don't know