caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: Ben Aurel <ben.aurel@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] native vs bytecode
Date: Wed, 6 Aug 2008 22:21:03 +0100	[thread overview]
Message-ID: <20080806212103.GA13743@annexia.org> (raw)
In-Reply-To: <74a4f4670808061258q30513bbdl446240feab3fdc36@mail.gmail.com>

On Wed, Aug 06, 2008 at 03:58:22PM -0400, Ben Aurel wrote:
> As I try to acquire more knowledge about Ocaml

Ben, your invitation to ocaml_beginners has now been approved so these
sorts of questions should go to that list.  There are many of the same
people, and we provide lots of help very quickly, but it keeps
beginners questions out of the way of the experts on this list.

> I made a bit of an unpleseant discovery today. I always was
> fascinated by the execution performance of Ocaml. But now I've
> learned, that this is only true for native binaries and I'm a little
> confused now:

OCaml really is very fast, _when_ you want it to be.

As with all programming, avoid premature optimizations, profile your
code to find out where it's spending its time, and rewrite those parts
that take the most time.

I rarely if ever use the bytecode compiler these days, since there is
no significant advantage to using it.  When I really need speed (after
profiling my program with gprof), I do the following steps in order
until the program is fast enough:

(1) Try to use more suitable data structures (eg. turning assoc-lists
into hash tables or maps).

(2) Rewrite critical functions to be tail recursive.

(3) Rewrite match expressions so that the common case has its own
match pattern and is written more efficiently.

(4) Look at memory usage of data structures and try to minimize.

(5) Turn lists into arrays and rewrite functional stuff using
for-loops.

(6) Turn to C (or even assembly) for critical inner functions.

With this strategy, OCaml programs at Red Hat are performing as well
as C code, and about an order of magnitude faster & an order of
magnitude lower memory usage than programs written in Python, which is
the main language used around here.

When you consider the environmental consequences of running many
virtualized machines in a data centre, order of magnitude reductions
in processor and RAM usage are *significant* (ie. muchos $$$).

> - is it possible to dynamically load native libraries into a native
> program?

Yes, in OCaml 3.11 Dynlink can do this.

> - is it possible to dynamically load bytecode libraries into a
> native program?

Not as far as I'm aware.

> - is it possible to dynamically load native libraries into a
> bytecode program?

Again, I don't think this is possible.

> - is it possible to dynamically load bytecode libraries into a
> bytecode program?

Yes, use the Dynlink module.

> - Are there any performance test that shows how bytecode programs
> stack up agains dynamic languages like ruby, perl and python?

If you look for the "Great Language Shootout" you'll find something.

Rich.

-- 
Richard Jones
Red Hat


  parent reply	other threads:[~2008-08-06 21:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-06 19:58 Ben Aurel
2008-08-06 20:05 ` [Caml-list] " Alain Frisch
2008-08-07  1:24   ` Matt Gushee
2008-08-07 12:46     ` Richard Jones
2008-08-06 20:09 ` Peng Zang
2008-08-07  7:38   ` Ulf Wiger (TN/EAB)
2008-08-06 21:21 ` Richard Jones [this message]
2008-08-07 13:02   ` Kuba Ober
2008-08-07 13:13     ` Kuba Ober
2008-08-07 22:12       ` Michael Ekstrand
2008-08-06 21:47 ` [Caml-list] " Mauricio Fernandez
2008-08-07  0:34 ` Haoyang Wang

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=20080806212103.GA13743@annexia.org \
    --to=rich@annexia.org \
    --cc=ben.aurel@gmail.com \
    --cc=caml-list@yquem.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).