caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Bruno Blanchet <bruno.blanchet@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Would it be possible to add automatic, region-based memory management to OCaml?
Date: Mon, 16 Apr 2018 17:31:57 +0200 (CEST)	[thread overview]
Message-ID: <1254277202.4888153.1523892717467.JavaMail.zimbra@inria.fr> (raw)
In-Reply-To: <587a5888-629b-1257-2035-4fefc0308ab5@gmail.com>

Dear all,

I implemented a stack allocator for OCaml 1.05 during my PhD (a long time
ago). If you want to have a look it is available at:
http://prosecco.gforge.inria.fr/personal/bblanche/escape-eng.html

Stack allocation can be considered as a particular case of
region allocation.

I can give a bit of feedback on this topic:

- There is sometimes a gain in using stack allocation,
but a very small one (<5%). It comes from reduced GC time and better
data locality (so better cache behavior).
This is because the OCaml GC is very good at dealing with
short lived data: they have almost no cost, since they are
already dead when collecting the young generation, so they
do not need to be copied.
This point might be a bit different with region allocation,
because you might hope to allocate long lived data in regions.

- The analysis required to do stack allocation is non trivial.
Doing that represents a lot of investment.
This is certainly also true for region allocation.

- If you want the analysis to be fully automatic, you
would certainly need to keep a GC: it is unlikely that
an automatic analyzer would manage to allocate all data
in regions, without having memory leaks.

- As already said before, there is no hope to have the whole
GC time go away.

If your goal is just performance, given the small gain and the effort 
required to make the static analysis, my feeling is that in practice,
it is not worth it. You have more to gain by optimizing
other aspects of your algorithm.

There are situations in which you do not want to have GC at all
(e.g. hard real time software). In that case, using other
allocation techniques makes sense, but an automatic region
analysis may not be sufficient: you would probably need
annotations to help the analyzer, so that the GC is not 
needed at all.

Best,
-Bruno

-- 
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

  reply	other threads:[~2018-04-16 15:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-09  5:20 ligand
2018-04-09 12:26 ` Basile Starynkevitch
2018-04-15 16:16   ` David Teller
2018-04-16 15:31     ` Bruno Blanchet [this message]
2018-04-17 10:10     ` [Caml-list] Would it be possible to add automatic, region-based Oleg

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=1254277202.4888153.1523892717467.JavaMail.zimbra@inria.fr \
    --to=bruno.blanchet@inria.fr \
    --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;
as well as URLs for NNTP newsgroup(s).