From: "Jon Harrop" <jon@ffconsultancy.com>
To: "'Diego Olivier Fernandez Pons'" <dofp.ocaml@gmail.com>,
<caml-list@inria.fr>
Subject: RE: [Caml-list] How to write an efficient interpreter
Date: Mon, 7 Nov 2011 06:45:40 -0000 [thread overview]
Message-ID: <0a4d01cc9d18$de73d1d0$9b5b7570$@ffconsultancy.com> (raw)
In-Reply-To: <CAHqiZ-+6oS6KtuNKoZ=Pt-7qrKFUVBSfk-v=RKeG+nPB8HZ+aw@mail.gmail.com>
If the language you are interpreting is quite declarative then piggy-backing
on OCaml's run-time either by writing an interpreter or by compiling to
OCaml code will be a big advantage. Writing a VM with a run-time as
efficient as OCaml's in this context is a *lot* of work compared to writing
an interpreter.
Unless there is a compelling reason not to, I'd stick with an interpreter
and just optimize it carefully. In particular, pay careful attention to your
data representations. When writing a term-rewriter, one of the biggest
performance gains I got was putting the value of each variable in the
variable itself so it could be looked up by dereferencing a pointer rather
than going via a hash table. Symbol tables are useful for similar reasons:
map identifiers onto small integer IDs and replace hash tables that have
identifiers as keys with an array indexed by ID. Beware the write barrier
though.
Also, when profiling I'd recommend logging the "kinds" of inputs your
interpreter sees. For example, try to spot patterns in the shapes of
expressions that your interpreter deals with and add special cases to the
expression type for those shapes and custom code to interpret them.
Cheers,
Jon.
prev parent reply other threads:[~2011-11-07 6:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-24 9:10 Diego Olivier Fernandez Pons
2011-10-24 9:58 ` Gabriel Scherer
2011-10-24 10:57 ` Gerd Stolpmann
2011-10-24 11:28 ` Xavier Leroy
2011-10-24 11:50 ` Diego Olivier Fernandez Pons
2011-10-24 12:33 ` Jérémie Dimino
2011-10-24 12:40 ` Gerd Stolpmann
2011-10-24 12:46 ` oliver
2011-10-24 12:58 ` Gerd Stolpmann
2011-10-24 21:01 ` oliver
2011-10-26 9:27 ` Diego Olivier Fernandez Pons
2011-11-07 6:45 ` Jon Harrop [this message]
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='0a4d01cc9d18$de73d1d0$9b5b7570$@ffconsultancy.com' \
--to=jon@ffconsultancy.com \
--cc=caml-list@inria.fr \
--cc=dofp.ocaml@gmail.com \
/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