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.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id D2F25BC6B for ; Thu, 16 Aug 2007 14:55:06 +0200 (CEST) Received: from ptb-relay02.plus.net (ptb-relay02.plus.net [212.159.14.213]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7GCt6Y7005394 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Thu, 16 Aug 2007 14:55:06 +0200 Received: from [80.229.56.224] (helo=beast.local) by ptb-relay02.plus.net with esmtp (Exim) id 1ILWgN-0005NS-Of; Thu, 16 Aug 2007 05:10:03 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: Joel Reymont Subject: Re: [Caml-list] High-performance bytecode interpreter in OCaml Date: Thu, 16 Aug 2007 04:58:49 +0100 User-Agent: KMail/1.9.7 Cc: caml-list@yquem.inria.fr References: <2B9157A5-ECA0-46EE-B628-840689224ACC@gmail.com> <200708151618.38165.jon@ffconsultancy.com> <3C3EDB59-44C1-4C3A-AD96-C762B986F39C@gmail.com> In-Reply-To: <3C3EDB59-44C1-4C3A-AD96-C762B986F39C@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200708160458.49873.jon@ffconsultancy.com> X-Miltered: at concorde with ID 46C4492A.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bytecode:01 ocaml:01 bytecode:01 lowercase:01 opcode:01 ocamlopt:01 compilation:01 lowercase:01 indirections:01 ocaml:01 2007,:98 frog:98 closures:01 closures:01 wrote:01 On Thursday 16 August 2007 00:26:49 Joel Reymont wrote: > On Aug 15, 2007, at 4:18 PM, Jon Harrop wrote: > > let rec compile bytecode = match bytecode with > > > > | 0x83::x::t -> > > > > let x = String.lowercase (string_of_int x) in > > let t = compile t in > > (fun k -> print_string x; k t) > > I'm curious, would this be any faster than doing whatever the 0x83 > opcode requires and then just invoking (compile t)? > > Does it actually make sense to convert the whole bytecode file into a > chain of closures and then execute it repeatedly? Would there be a > huge gain compared to interpreting every time? > > I guess it would make sense if closures could be compiled into > machine code "just in time" or if my VM was compiled using ocamlopt. > I'm not sure, though, so I'm looking for input. Yes, this is not compilation, it just hoists code from the inner loop (such as String.lowercase and string_of_int in that case) and replaces dynamic dispatch with static dispatch. The former is usually the more important of the two optimizations, particularly if you can hoist lookups and replace them with single indirections. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. OCaml for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/?e