Compiling Node on Mac OS X using LLVM

405 views
Skip to first unread message

Matthew P. Tilchen

unread,
Jun 25, 2010, 1:23:12 PM6/25/10
to nod...@googlegroups.com
I thought I would post this and potentially save some collective
minutes for those who are compiling Node often. I have been using the
LLVM compiler that ships with Apple's Developer Tools package for Snow
Leopard and I noticed that it compiles Node a bit faster than straight
GCC. Here are the results of running "time make" for LLVM and GCC
configurations:

LLVM Compile (llvm-gcc, llvm-g++)
-----------------------
real 2m22.703s
user 2m6.522s
sys 0m13.459s

GCC Compile (gcc, g++)
------------------------
real 3m52.327s
user 3m32.908s
sys 0m17.426s

I have a 2 GHz C2D, 4GB Macbook running 10.6.4. The versions of LLVM
and GCC are 2.6 and 4.2 respectively. For those who have not already
tried, and have the developer tools installed, you just need to
execute "export CC=llvm-gcc CXX=llvm-g++" in the shell before running
configure and make.

A minute and a half is a pretty decent improvement. The 2.6 version of
the LLVM compiler still uses gcc in the front end for parsing and LLVM
in the back end. As of version 2.7 the front end can handle C++ so you
can drop the gcc front end as well. When it comes in the next release
of Apple's dev tools you can substitute "clang" for both "llvm-gcc"
and "llvm-g++". I expect further reduction in compilation time with
version 2.7.

For those compiling on Linux/BSD/etc you can at least download the
latest version from llvm.org. I am not sure if they publish pre-built
debian packages, rpms or what have you.

I have not yet compared the performance of builds of node using the
two different compilers. I would expect very little difference in most
node applications as they are most likely IO-bound. Perhaps if you
have a CPU-bound application you might see some gains with an
LLVM-built node. Two layers of JIT are better than one :)

Have fun.

-MT

Marshall Culpepper

unread,
Jun 25, 2010, 1:45:22 PM6/25/10
to nod...@googlegroups.com
I'd be interested in seeing runtime benchmarks too.. this is really cool stuff!


--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.


Astro

unread,
Jun 25, 2010, 2:29:24 PM6/25/10
to nod...@googlegroups.com
Matthew P. Tilchen wrote:
> I thought I would post this and potentially save some collective
> minutes for those who are compiling Node often. I have been using the
> LLVM compiler that ships with Apple's Developer Tools package for Snow
> Leopard and I noticed that it compiles Node a bit faster than straight
> GCC. [...]

Speed is not its only advantage: I've used clang++ for development of
node-expat because g++ error messages kept me riddled. That may
unfortunately not be the case with llvm-g++.

> For those compiling on Linux/BSD/etc you can at least download the
> latest version from llvm.org. I am not sure if they publish pre-built
> debian packages, rpms or what have you.

http://packages.debian.org/lenny/llvm-gcc-4.2

> [...] Two layers of JIT are better than one :)

LLVM is not a JIT compiler, or did I miss anything?

Matthew P. Tilchen

unread,
Jun 25, 2010, 3:51:32 PM6/25/10
to nod...@googlegroups.com
On Fri, Jun 25, 2010 at 2:29 PM, Astro <as...@spaceboyz.net> wrote:
> Matthew P. Tilchen wrote:
>> I thought I would post this and potentially save some collective
>> minutes for those who are compiling Node often. I have been using the
>> LLVM compiler that ships with Apple's Developer Tools package for Snow
>> Leopard and I noticed that it compiles Node a bit faster than straight
>> GCC. [...]
>
> Speed is not its only advantage: I've used clang++ for development of
> node-expat because g++ error messages kept me riddled. That may
> unfortunately not be the case with llvm-g++.

How true. The static analysis capabilities and the error messages
produced by clang are far superior to those of gcc. Now that version
2.7 of clang/llvm supports C++ I am betting that you can expect to
have similar benefits when compiling C++.

>> For those compiling on Linux/BSD/etc you can at least download the
>> latest version from llvm.org. I am not sure if they publish pre-built
>> debian packages, rpms or what have you.
>
> http://packages.debian.org/lenny/llvm-gcc-4.2
>
>> [...] Two layers of JIT are better than one :)
>
> LLVM is not a JIT compiler, or did I miss anything?
>

LLVM definitely has JIT capabilities. By default llvm compiles your
code all the way to a native executable but you can instruct it to
stop at the intermediate/bytecode level. You can then let llvm JIT
this output at runtime using the llvm runtime libraries. A good basic
example of this can be found here:

http://llvm.org/docs/GettingStarted.html#tutorial4

I guess I was just poking fun at the idea of using JIT on top of JIT
(js/v8) more than anything else. I am not sure a project like Node
would even benefit from runtime optimization of its native parts but
it might be interesting to see. It seems like the LLVM runtime
optimization library would actually be something one could use to
implement the JIT in V8.

-MT

Marco Rogers

unread,
Jun 25, 2010, 9:07:37 PM6/25/10
to nodejs
What's the best way to replace the insert these into the build
configuration?
Reply all
Reply to author
Forward
0 new messages