caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David House <dhouse@janestreet.com>
To: David MENTRE <dmentre@linux-france.org>
Cc: Gerd Stolpmann <gerd@edgespring.com>,
	Oliver Bandel <oliver@first.in-berlin.de>,
	 caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Behaviour of an OCaml program: any possible GC improvement?
Date: Thu, 25 Oct 2012 08:37:00 +0100	[thread overview]
Message-ID: <CAK=fH+iiFEAQBhq3QGhZb2KFaPvZePRjkLtSbzv6y3xvO9N1Fw@mail.gmail.com> (raw)
In-Reply-To: <CAC3Lx=YAezJ_F52P1DJc_ee61Su+QZC+cJN_EgAkYGx902GUBw@mail.gmail.com>

On Thu, Oct 25, 2012 at 7:48 AM, David MENTRE <dmentre@linux-france.org> wrote:
>> Some improvement is also
>> possible with simple tricks, e.g. if you have something like
>>
>> Number 0
>>
>> where Number is from an algebraic type, and you use this term frequently,
>> consider to add a constant for it,
>>
>> let n0 = Number 0
>>
>> so this isn't reallocated all the time
>
> Thanks for the trick.

As Martin pointed out, this isn't necessary for Number 0. Constant
expressions are statically allocated. If you have two functions
returning Number 0, you'll get two of them, but they'll still be
statically allocated (so calling that function does not allocate for
Number).

This is actually even true of string literals, which are mutable:

# let f () = "foo";;
val f : unit -> string = <fun>
# let x = f ();;
val x : string = "foo"
# let y = f ();;
val y : string = "foo"
# x.[0] <- 'g';;
- : unit = ()
# y;;
- : string = "goo"

But other, similar tricks are worthwhile. For example, in async, it is
very common to write "return ()" for the deferred that is immediately
determined with value (). But doing so does a function call and
allocates a deferred. So we have [Deferred.unit] for this common case.

  reply	other threads:[~2012-10-25  7:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-24 10:08 David MENTRE
2012-10-24 10:33 ` John Whitington
2012-10-24 12:30   ` David MENTRE
2012-10-24 12:39     ` John Whitington
2012-10-24 12:45       ` Edgar Friendly
2012-10-24 12:53         ` John Whitington
2012-10-24 13:19       ` David MENTRE
2012-10-24 13:27         ` John Whitington
2012-10-24 13:38         ` Oliver Bandel
2012-10-24 14:30           ` David MENTRE
2012-10-24 15:09             ` David MENTRE
2012-10-24 16:07               ` AW: " Gerd Stolpmann
2012-10-24 17:23                 ` Martin Jambon
     [not found]               ` <1351094817.12207.11@samsung>
2012-10-25  6:48                 ` David MENTRE
2012-10-25  7:37                   ` David House [this message]
2012-10-24 10:38 ` Török Edwin
2012-10-25 10:06   ` David MENTRE
2012-10-25 10:16     ` Török Edwin
2012-10-25 10:19       ` David MENTRE
2012-11-07 11:52     ` David MENTRE

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='CAK=fH+iiFEAQBhq3QGhZb2KFaPvZePRjkLtSbzv6y3xvO9N1Fw@mail.gmail.com' \
    --to=dhouse@janestreet.com \
    --cc=caml-list@inria.fr \
    --cc=dmentre@linux-france.org \
    --cc=gerd@edgespring.com \
    --cc=oliver@first.in-berlin.de \
    /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).