Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] mark_slice, sweep_slice, oldify
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: [Caml-list] mark_slice, sweep_slice, oldify
> With the aid of gprof I noticed that my program spends most of the time
> of the computation in three functions `mark_slice', `sweep_slice' and
> `oldify' (see below the output of gprof obtained after the computation
> of some products of polynomials).
> 
> What does this exactly mean?  This is the generational garbage
> collector, right?

Yes.  "oldify" is the minor copying collector, and "mark_slice" and
"sweep_slice" are the incremental mark-and-sweep major collector.

> May I low the cost of GC?

There is no general answer to this question.  As a rule of thumb,
allocating small, short-lived blocks (that die before the next minor
collection) is very cheap; longer-lived objects cost significantly more.

You could try to play with the GC settings (either at start-up via the
CAMLRUNPARAM environment variable, or programmatically via the Gc.get
and Gc.set functions).  E.g. if many of your blocks survive a minor
collection but die shortly thereafter, increasing the size of the
minor heap could help.  If your program runs for a short amount of
time, you could try increasing the "overhead" parameter to, say, 100,
to make the incremental major collector work less.

The GC statistics returned by Gc.stat could also be of interest,
although you need a bit of background in garbage collection to
understand what they really mean :-)

Sometimes, the program can be rewritten to eliminate allocation of
intermediate data structures.  This is known as "deforestation" in the
literature.  For a simple-minded example: if you often sum three
polynomials, instead of writing "poly_add x (poly_add y z)"
(which causes the intermediate polynomial y + z to be allocated),
write a "poly_add3" function that will sum three polynomials in one go.

Good luck,

- Xavier Leroy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr