On 11/18/2010 09:51 AM, Eray Ozkural wrote: > A program I wrote constructs a lot of small lists, and strings and > discards them. It's a search algorithm. I profiled this code and saw > that garbage collection takes significant time. > > In C++, we can write custom allocators to optimize the data structures > that cause such slowdowns. Any recommended strategies in ocaml?
The OCaml garbage collector exposes a variety of tuning parameters through the Gc module[1] and the OCAMLRUNPARAM environment variable[2]. I would tweak those. In particular, I would recommend increasing the minor heap size so that more of your data can be quickly discarded. You can also increase the space overhead, thereby causing the GC to be less aggressive at the expense of higher memory usage/more waste. Lastly, I often increase the heap increment to allow memory to allow the heap to expand more quickly, but I do not know if that will help in your case or not. I have documented my practices more thoroughly at my blog[3]. As I see it, the biggest gains will be by tuning your code and your minor heap size so that ephemeral structures never hit the major heap. My rule of thumb is that one "work unit", if you have such a concept, should fit in the minor heap. Collecting dead structures from the minor heap is fast; moving a structure to the major heap only to have it be unreachable by the next GC cycle can cause substantial GC thrashing. You're on to a good start, though, by measuring. I use gprof heavily as I tweak my code's performance. - Michael 1. http://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html 2. http://caml.inria.fr/pub/docs/manual-ocaml/manual024.html#toc96 3. http://elehack.net/michael/blog/2010/06/ocaml-memory-tuning _______________________________________________ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs