Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
HLVM is now garbage collected!
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] HLVM numerical performance
On Monday 09 March 2009 09:04:57 Jan Kybic wrote:
> > The OCaml Forge has kindly accepted to host the HLVM project:
> >
> >
> Hello. Just out of curiosity:
> I recall reading that one of your priorities for HLVM is performance of
> numerical code. 

HLVM aspires to provide the following benefits over OCaml:

. High performance numerics (often 2-4x faster than OCaml on x86).

. High performance polymorphism: polymorphic definitions are instantiated for 
different types.

. More numeric types (float32, complexes, low-dimensional vectors and 

. More optimizations for the benefit of numerical computing: common 
subexpression elimination, hoisting of loop invariants, inlining of function 
arguments to higher-order functions.

. Faster and easier FFI for external libraries like FFTW and LAPACK.

. Dynamic capabilities such as generic printing, hashing, comparison, 
serialization and run-time type information.

. Community led development: you can contribute to the open source HLVM code 

. Commerce friendly design so it will be viable for you to buy and sell 
libraries written for HLVM.

. A common language run-time so you can safely consume and produce libraries 
written in any languages with implementations that target HLVM.

> Does it mean that you expect numerical code to run faster than natively
> compiled (with ocamlopt) Ocaml? 

Absolutely. Most numerical code already runs a lot faster in HLVM than it does 
in ocamlopt if you disable GC in any inner loops that act upon arrays. In the 
future, I expect HLVM to be a lot faster still because it will generate SSE 
instructions (using LLVM's vector intrinsics) and perform many optimizations 
of its own (such as hoisting the GC code automatically).

> Do you have any experiments so far to support this?

Yes. The "" file from the HLVM subversion repository contains over 500 
lines of test code that includes a few simple benchmarks. Here is a 
comparison of the performance of ordinary OCaml with the best performance I 
have been able to obtain using HLVM:

Float Fibonacci (recursive floating point functions)
OCaml: 6.10s
HLVM:  1.74s  3.5x faster than ocamlopt

Mandelbrot (complex arithmetic)
OCaml: 4.39s
HLVM:  1.89s  2.3x faster than ocamlopt

Sieve of Eratosthenes (int arrays)
OCaml: 14.9s  (had to use big arrays)
HLVM:  7.05s  2.1x faster than ocamlopt

As you can see HLVM is already generating much faster code than ocamlopt. Note 
that the OCaml code can be improved (e.g. by avoiding OCaml's complex number 
type) but the point is that idiomatic code is much faster with HLVM.

> I am doing large scale numerical calculations in Ocaml and performance
> is always an issue for me.

A lot of people have adopted OCaml for number crunching and string munging 
(bioinformatics). Although ocamlopt is an excellent compiler, HLVM has shown 
that it is possible to do much better still. I hope HLVM will form the 
backbone of an OCaml variant designed specifically for technical computing.

Dr Jon Harrop, Flying Frog Consultancy Ltd.