3 ms·
You are referring to an AST interpreter, right?
by barrkel 11y ago
You are referring to an AST interpreter, right?
- JoeAltmaier 11y agoMore like this variant: http://lafo.ssw.uni-linz.ac.at/papers/2012_DLS_SelfOptimizingASTInterpreters.pdf http://lafo.ssw.uni-linz.ac.at/papers/2012_DLS_SelfOptimizin... Its a natural extension to derive objects optimized for common cases e.g. integer increment vs generic add expression. The bytecode idea adds complexity and doesn't actually speed up unless you add JIT conversion to native, which makes it a compiler again. The virtual method penalty is way overstated. Its still 10X faster than an interpreter. And 10X slower than a compiler. A decent compromise, and easily written in a weekend for any simple language.
- LnxPrgr3 11y agoDo you have benchmarks for this? The linked paper only evaluates performance of optimizations applied on top of this idea, and the idea vs. Rhino. Besides, not all bytecode interpreters are made equal: http://vvm.lip6.fr/publications/9806PLDI.ps.gz http://vvm.lip6.fr/publications/9806PLDI.ps.gz.
- JoeAltmaier 11y agoMy data is old - various control languages, BASIC, RPN style expression engine. Each time about the same performance. Go ahead and implement a bytecode machine, but you lose two ways: the time to write that extra engine, and the loss of semantics. In the interplet (ok, AST) interpreter, you can add debugging features that 'understand' the intent e.g. still know a loop is a loop. That's cool and powerful.
- sklogic 11y agoIt's better to know that loop is a loop just from a CFG, even if it's implemented with a goto and if. In this case stripping source language semantics may be useful.
- JoeAltmaier 11y agoSo true! A peephole optimizer can operate on constructs no matter how they're generated, and streamline them (use custom objects for common/slow cases). But for debugging, its nice to offer diagnostic or control features (e.g. execute 1000 times then break).
- sklogic 11y agoYou still have your loops in CFG, identifying back edges and extracting loop induction variables is mechanical. And you can lower any amount of debugging information out of your high level AST structures. No need to stay in AST to have it all.
- munificent 11y ago> The bytecode idea adds complexity and doesn't actually speed up unless you add JIT conversion to native, which makes it a compiler again. In every language implementation I've worked with, bytecode led to a large improvement in performance. > The virtual method penalty is way overstated. This makes me think your data is outdated. It's more about the loss of locality today than it is virtual method dispatch. With a tree-walk interpreter, your "code" is spread all throughout memory and executing involves jumping all over the address space. That kills your cache. > Its still 10X faster than an interpreter. And 10X slower than a compiler. Those numbers don't mean anything without context. What are the semantics of the language? What's the object representation? The memory model? How are local variables managed? > easily written in a weekend for any simple language. Call me crazy, but I don't think a bytecode compiler takes any more time than that either.