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
Does the gc avoid collecting arrays of ints
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-07-23 (20:33)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] Does the gc avoid collecting arrays of ints
On Monday 23 July 2007 18:35:40 Till Varoquaux wrote:
> Looking at ocaml's source code I see that the values representing
> arrays have a tag representing the type of their content (I'm guessing
> boxed/unboxed). Does this mean that a bidimensional array containing
> ints will only be explored in one direction during garbage collection?
> If so, how do the compare to Bigarray's (I'm guessing they still are
> slower).

My gut feeling is that an array of arrays would be faster. You might also like 
to abstract away a single array behind the interface of a multidimensional 
array (particularly if you're on 64-bit).

However, there are some wierdnesses here. The GC treats the stack and arrays 
of pointers atomically, traversing all elements in one go. So having a single 
large array of boxed values (like an array of arrays or an array of lists in 
a Hashtbl) can cause significant stalls in the incremental GC.

I found this performance characteristic whilst optimizing Smoke's worst case 
performance, which is very important for such soft-real-time applications. I 
had "optimized" by memoizing stuff and things in a hash table, which turned 
out to slow the GC down enormously whenever it stumbled upon the hash table.

Incidentally, I get the distinct impression that Chistophe's question isn't 
going to get answered until the ICFP is done and dusted and everyone has 
recouperated. ;-)

Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists