From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=AWL,SPF_FAIL autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 8CAADBBAF for ; Wed, 6 Aug 2008 23:21:04 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAN2ymUhQRFuw/2dsb2JhbACteA X-IronPort-AV: E=Sophos;i="4.31,316,1215381600"; d="scan'208";a="15774954" Received: from furbychan.cocan.org ([80.68.91.176]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 06 Aug 2008 23:21:04 +0200 Received: from rich by furbychan.cocan.org with local (Exim 4.63) (envelope-from ) id 1KQqRL-0005BF-8W; Wed, 06 Aug 2008 22:21:03 +0100 Date: Wed, 6 Aug 2008 22:21:03 +0100 To: Ben Aurel Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] native vs bytecode Message-ID: <20080806212103.GA13743@annexia.org> References: <74a4f4670808061258q30513bbdl446240feab3fdc36@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <74a4f4670808061258q30513bbdl446240feab3fdc36@mail.gmail.com> User-Agent: Mutt/1.5.13 (2006-08-11) From: Richard Jones X-Spam: no; 0.00; bytecode:01 ocaml:01 ocaml:01 bytecode:01 compiler:01 hash:01 recursive:01 arrays:01 dynlink:01 dynlink:01 beginners:01 beginners:01 wrote:01 binaries:01 stack:01 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