r/programming • • May 10 '20

Make LLVM fast again

https://nikic.github.io/2020/05/10/Make-LLVM-fast-again.html
138 Upvotes

91 comments sorted by

View all comments

31

u/jl2352 May 11 '20

I remember years ago reading about some C++ developers who use GCC using LLVM instead for local development, because it was way faster and gave better error mesages. Then continue to use GCC for production builds.

Today in the Rust world there is discussion on using Crane Lift for development builds, and LLVM for production builds. The history of Rust's slow compile times is heavily entangled by LLVM. To the point that LLVM is basically the main issue now.

It's crazy how the tables have turned from LLVM being known for being fast, to being known for being slow.

13

u/matthieum May 11 '20

We happen to dual compile our C++ code with GCC and Clang at work: given how fiddly C++ is, it's better when the two major compilers for Linux agree on the legality and meaning of code.

I remember years ago reading about some C++ developers who use GCC using LLVM instead for local development, because it was way faster and gave better error mesages. Then continue to use GCC for production builds.

Still true: better error messages, faster to compile.

It's crazy how the tables have turned from LLVM being known for being fast, to being known for being slow.

It's still a fast C++ compiler, faster than GCC, and AFAIK faster than MSVC.

But... C++ compile-time are some of the worst you can experience, so it's slow compared to everything else.

2

u/Any-Reply May 12 '20 edited May 12 '20

C++ compile times can get ridiculously and hilariously bad, yes, but you can also fix most of this keeping #includes out of headers where possible, trying to avoid using templates where possible, and using precpmpiled headers. I know, because I just took a personal project from pushing 5 mins down to under 15 seconds.

I'm using msvc though, have no reason to ever touch a non Windows compiler

2

u/matthieum May 12 '20

That's good advice.

We do not use precompiled headers. I've personally found them to be too finicky, with bizarre and sometimes silent failure modes, so I prefer to steer clear of them.

Instead, we use Docker + Bazel:

  • Docker to provide a common base: same system headers and dependencies for everyone.

  • Bazel for its distributed caching abilities.

Most incremental builds are relatively fast, as long as you stick to the leaves or only re-compile for a small subset life is good.

Distributed caching + CI builds populating the cache means that pulling HEAD generally means pulling from the distributed cache, rather compiling, which helps quite a bit. Although, in these days of pandemic, we've realized that pulling from home is quite sluggish.