Version française
Home     About     Download     Resources     Contact us    
Browse thread
OCaml and Boehm
[ 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] OCaml and Boehm
On Saturday 11 April 2009 10:46:13 Basile STARYNKEVITCH wrote:
> Lukasz Stafiniak wrote:
> > Hi,
> >
> > Is the OCaml runtime Boehm-safe? That is, can it be run with Boehm
> > turned on and traversing OCaml's heap? (So that the OCaml heap can
> > provide roots to Boehm.) And if not, could it be patched to make it
> > Boehm-safe in this sense?
>
> Probably not. Because I am not sure of what you mean by Boehm-safe,
> since Boehm's GC is conservative and do not make much promises.

Boehm's GC breaks on various code, most notably code that "hides" pointers to 
reachable data in an indirect form. The most famous example that breaks Boehm 
is the (admittedly awful and technically illegal) pointer bump trick used in 
Numerical Recipies to bring the wonderous starting-at-one indexes of Fortran 
to the C world. Boehm fails to recognise the bumped pointers as references 
into reachable data and goes right ahead and deallocates all of your 
numerical arrays for you.

> There is a reason for all this. The major strength of Ocaml runtime is
> its robustness and its efficiency. The efficiency of Ocaml GC is of
> paramount importance (it supports very high allocation rate, which is
> out of reach for the Boehm collector; and big allocation rate is typical
> of most functional programs; the typical allocation speed within the
> Ocaml runtime is at least one or two order of magnitudes faster than
> that of GC_malloc; a typical GC_malloc is by itself a bit slower than a
> libc malloc.).

Regarding OCaml vs libc malloc, I had always assumed that but HLVM appears to 
have proven otherwise. It uses malloc and free directly with no optimization 
whatsoever yet it is now well within 2x the performance of OCaml on the 
allocation and GC intensive 10-queens benchmark.

Boehm's allocator is asymptotically slower than malloc, of course.

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e