English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
High-performance bytecode interpreter in OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-08-16 (12:55)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] High-performance bytecode interpreter in OCaml
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