caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Florian Hars <florian@hars.de>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Where does Ocaml spend all the time?
Date: Thu, 28 Jun 2001 10:37:24 +0200	[thread overview]
Message-ID: <20010628103724.A11414@pauillac.inria.fr> (raw)
In-Reply-To: <20010628101635.A25747@hars>; from florian@hars.de on Thu, Jun 28, 2001 at 10:16:35AM +0200

> I have written an ocaml program, which is about an order of magnitude
> slower than a similar C program, and now I am wondering what to do.
> According to gprof, I have neiter written nor called most of the
> top-scoring functions in my program:
> Only the third and fourth entry seem to do anything "useful", the rest
> looks like administrative overhead to me. What are these functions
> doing?

mark_slice and sweep_slice are the major garbage collector.
oldify is the minor garbage collector.
string_equal is the string comparison operator (i.e. Caml's = operator
at type string->string->bool).

> Are there any general hints on how to write ocaml programs for efficiency?
> Like, don't use functional updates for records to reduce garbage?

That might be a possibility, depending on the size of the records.
However, heap allocation of short-lived data structures is quite cheap,
while some forms of in-place updates can be quite expensive
(in particular, storing a pointer to a young object in an old object).
So, the answer is not clear-cut.

At any rate, the GC-related functions account for only 25% of the
running time (which is typical for symbolic processing, but a bit high
for numerical processing), so the "order of magnitude" slowdown that
you mention corresponds to other factors than just GC overhead.
My experience is that carefully written Caml code always deliver at
least 50% of the performance of equivalent, carefully written C code.

It is true, however, that tuning Caml code for performance is not
obvious without a good knowledge of the compiler internals.  However,
the "making code run fast" section of the OCaml Questions and Answers
might help:
        http://caml.inria.fr/ocaml/QandA.html

- 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


  parent reply	other threads:[~2001-06-28  8:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-28  8:16 Florian Hars
2001-06-28  8:34 ` Sven LUTHER
2001-06-28  8:37 ` Xavier Leroy [this message]
2001-06-28 10:02   ` Florian Hars
2001-07-02 13:16     ` Xavier Leroy
2001-07-02 16:21       ` Chris Hecker
2001-06-28  8:39 ` Daniel de Rauglaudre
2001-06-28 10:02   ` Florian Hars
2001-06-28  8:50 ` Remi VANICAT

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=20010628103724.A11414@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=florian@hars.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).