From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: Francois Berenger <berenger@riken.jp>
Cc: caml-list@inria.fr
Subject: AW: [Caml-list] What is triggering a lot of GC work?
Date: Mon, 25 Feb 2013 14:31:13 +0100 [thread overview]
Message-ID: <1361799073.2723.5@samsung> (raw)
In-Reply-To: <512AC78E.7070908@riken.jp> (from berenger@riken.jp on Mon Feb 25 03:08:14 2013)
Am 25.02.2013 03:08:14 schrieb(en) Francois Berenger:
> Hello,
>
> Is there a way to profile a program in order
> to know which places in the source code
> trigger a lot of garbage collection work?
>
> I've seen some profiling traces of OCaml programs
> of mine, sometimes the trace is very flat,
> and the obvious things are only GC-related.
>
> I think it may mean some performance-critical part
> is written in a functional style and may benefit
> from some more imperative style.
This is really a hard question, and I fear an allocation profiler
cannot always answer it. Imperative style means to use assignments, and
assignments have often to go through caml_modify, and are not as cheap
as you would think. In contrast, allocating something new can usually
avoid caml_modify.
This can have counter-intuitive consequences. Yesterday I sped an
imperative program up by adding allocations! The idea is so strange
that I need to report it here. The program uses an array for storing
intermediate values. Originally, there was only one such array, and
sooner or later this array was moved to the major heap by the GC.
Assigning the elements of an array in the major heap with young values
is the most expensive form of assignment - the array elements are
temporarily registered as roots by the OCaml runtime. So my idea was to
create a fresh copy of the array now and then so it is more often in
the minor heap (the array was quite small). Assignments within the
minor heap are cheaper - no root registration. The program was 10%
faster finally.
My general experience is that optimizing the memory behavior is one of
the most difficult tasks, especially because the OCaml runtime is
designed for functional programming, and short-living allocations are
really cheap. Usual rules like "assignment is cheaper than new
allocation" just do not hold. It depends.
Gerd
>
> Regards,
> F.
>
>--
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
--
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de
Creator of GODI and camlcity.org.
Contact details: http://www.camlcity.org/contact.html
Company homepage: http://www.gerd-stolpmann.de
------------------------------------------------------------
next prev parent reply other threads:[~2013-02-25 13:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-25 2:08 Francois Berenger
2013-02-25 8:02 ` Mark Shinwell
2013-02-25 10:32 ` ygrek
2013-02-26 3:46 ` Francois Berenger
2013-02-26 4:29 ` ygrek
2013-02-25 13:31 ` Gerd Stolpmann [this message]
2013-02-25 15:45 ` AW: " Alain Frisch
2013-02-25 16:26 ` Gerd Stolpmann
2013-02-25 16:32 ` Gabriel Scherer
2013-02-25 16:52 ` [Caml-list] OCaml benchmarks Török Edwin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1361799073.2723.5@samsung \
--to=info@gerd-stolpmann.de \
--cc=berenger@riken.jp \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox