Merge: Optimize variable access in the nitvm
authorJean Privat <jean@pryen.org>
Wed, 18 Mar 2015 09:21:09 +0000 (16:21 +0700)
committerJean Privat <jean@pryen.org>
Wed, 18 Mar 2015 09:21:09 +0000 (16:21 +0700)
The first commit change the way variables are accessed in the vm.

For each method or attribute block (to init them), we recursively go into the AST to find each variable declaration in order to give them a fixed position (in the environment).
This is a small recursion since we only need to go deeper for block constructions.

During execution, the access are made by using this position instead of using the old ```HashMap[Variable, Instance]``` of the interpreter.

The second commit completely replace the frames of the interpreter to avoid allocation of these hashmaps in the virtual machine, the commit is pretty verbose but this is mainly code from the interpreter.

The overall gain is good since the vm is now faster than the interpreter :)

For the small benchmark ```nitvm src/nit.nit tests/base_simple3.nit```, we have 2.9 seconds with nitvm before.
Now, nitvm take 2.67 seconds, 2.83 for niti: 8% better.
The overall gain on a few benchmarks I made are between 5% and little more than 10% but always positive.

Pro: faster
Con: work will be required to maintain the two engines...

Pull-Request: #1184
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>


Trivial merge