A new compiler

I know many of you switched to Clang/LLVM the second it shipped with Snow Leopard, but I've been a bit timid with regard to that switch. So, I've been merrily compiling Pear Note with gcc 4.2 until very recently. A few weeks ago, after listening to the MDN Show episode 15 in which Danny Greg praises it and Kevin Hoctor gives John Fox a hard time about not switching to it, I decided to give it a go.

I had actually tested Clang/LLVM out a few months ago just to see what problems it would find with my code. It found around 80 issues, which I fixed, but I kept building with gcc, fearing the unknown of a new compiler.

After hearing that other devs had made the switch long ago in their production code, I decided to give it a go. To be clear, I switched to using what Apple is shipping with the Snow Leopard developer tools. Apple calls this Clang LLVM 1.0 (I'm not sure where that version number came from). So, I made the switch for Pear Note 1.4 (the current 1.4 beta is built using Clang/LLVM).

Since the switch, I have not hit any problems. I was worried that given how new the tools were there might be little bugs. Working around compiler problems is a pain, but I have not found any problems with using Clang/LLVM.

Is it faster?

There are two sides to performance improvements - faster code produced by the compiler and faster compilation. I really can't tell if the code produced is any faster. Given that Pear Note is a user application and most of the computationally intensive operations (encoding video, etc.) occur in shared libraries rather than Pear Note itself, it's not immediately apparent whether the code is faster. I could have written a test application that used some of the model code from Pear Note and tested it with both compilers, but I wasn't that motivated.

Compilation speed is a different story. It was immediately obvious that Clang/LLVM was much faster building Pear Note than gcc was. Doing some tests, build time dropped from an average of 60 seconds with gcc to an average of 32 seconds with Clang/LLVM. That's especially impressive when you consider that much of the build involves many pieces that will not change with this switch (building nibs, python and shell scripts, the preprocessor). Given that, it appears that Clang/LLVM is much more than twice as fast as gcc. And remember that this is Clang/LLVM 1.0. My understanding is that Clang/LLVM tip-of-trunk is much faster than this, so more improvements are on the way.

The moral of the story here is Clang/LLVM is good stuff. It gives you much more useful and more plentiful warnings/errors and it builds much faster than gcc. If you're a Mac developer and you're building on Snow Leopard (though you can still target earlier OS releases, as I'm targeting 10.5), you should at least try it out.

Comments

There are no comments yet