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
caml_oldify_local_roots takes 50% of the total runtime
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-10-25 (18:21)
From: Markus Mottl <markus.mottl@g...>
Subject: Re: [Caml-list] caml_oldify_local_roots takes 50% of the total runtime

On 10/25/06, Hendrik Tews <> wrote:
> >From the comments of Damien Doligez in a related thread in
> I got the impression that there is extra punishment for
> caml_local_roots. Should the situation improve if I organize the
> 350.000 ocaml node pointers on the ocaml side via one local root
> (asumming this information is needed not so often)?

This is a known problem: the OCaml-runtime calls this function
(caml_oldify_local_roots) at each minor collection.  The function iterates
over all local roots, and since minor collections happen quite often, this
naturally leads to excessive CPU-usage - even if hardly anything else is
going on.

To work around this problem you should store pointers to the C++-objects on
the C++-side, and e.g. associate them with finalized OCaml-values, or
handles which allow you to explicitly deallocate the objects.

It would be great if the GC could be improved in situations where there are
many local roots.  This is a pretty common problem when interfacing
non-trivial third party libraries, and the clumsy workarounds require
writing somewhat error-prone code.

Best regards,

Markus Mottl