Fukubukuro¶
Fukubukuro (mystery bag) is a proof-of-concept implementation of something that might help to identify overhead in the current VM implementation.
Benchmarks: Other interpreters¶
| Tool | Time | Comment |
|---|---|---|
| C | 0.002s | It seems GCC 4.3.2 compiles it down to a single Core 2 Duo cycle. |
| Java | 0.004s | Optimized to constant time for int, about two cycles for long. |
| Clojure 1.1 | 0.015s | Very fast when using ints and zero?. |
| TraceMonkey (estimated) | 0.06s | Tested with Firefox 3.1b3pre on OS X (Wow!) |
| Ruby 1.9.2 | 0.34s | YARV optimizes such code very well. |
| SquirrelFish (estimated) | 0.4s | Tested with WebKit 3.2.1 / 5525.27.1 on OS X |
| SpiderMonkey (estimated) | 0.8s | Tested with Firefox 3.0.6 on OS X |
| JRuby 1.1.7 w/ Java 1.6 | 1.0s | JRuby is always hard to benchmark. Should be faster than MRI Ruby 1.9 for longer benchmarks. |
| Python 2.5 | 1.34s | I expected more... |
| Python 2.6 | 1.4s | Same. |
| Rhino 1.7RC2 | 1.4s | Easy to install and play with on the console. |
| Ruby 1.8 | 1.9s | We all know that Ruby 1.8 is slow :) |
| Safari (estimated) | 2.0s | Safari 3.2.1 |
| Groovy 1.6-RC-1 | 2.7s | Much better, kudos to the Groovy guys. But still slower than Ruby ;) |
| Groovy 1.5.7 | 6.3s | Slow! |
Benchmarks: Fukubukuro vs. original AmberVM¶
| Fukubukuro 1 w/ Ruby 1.9.1 | 8.2s | Original version, compiled by hand, using Fixnum. |
| Fukubukuro 2 w/ Ruby 1.9.1 | 8.9s | Using Float. |
| Fukubukuro 3 w/ Ruby 1.9.1 | 14.5s | Using Float container objects. |
| Fukubukuro 4 w/ Ruby 1.9.1 | 9.4s | Using Integer literals in Numeric container objects with increment and _const methods. |
| Fukubukuro 5-6 w/ Ruby 1.9.2 | 9.0s | Ruby 1.9.2 seems to be faster than 1.9.1 :) |
| Fukubukuro 7 w/ Ruby 1.9.2 | 8.0s | using precompiled while loop |
| Fukubukuro 8 w/ Ruby 1.9.2 | 13.1s | fixing illegal optimizations |
| RVM: ECMA 1 w/ Ruby 1.9.1 | 232s | This was the reason for Fuku. |
| AmberVM: ECMA 2 -o w/ Ruby 1.9.2 | 184s | Improved. |
| AmberVM: ECMA 2 -o w/ Ruby 1.9.2* | 80s | More improved. |
| AmberVM: ECMA 3 -o w/ Ruby 1.9.2 | 112s | New parser, many changes. |
The program (JavaScript):
var a = 0;
var i = 4000000;
while (i != 0) {
a += 1;
i -= 1;
}
You can start the benchmark with:
time ruby19 -wIlib bin/ambervm -lecma_fuku examples/simple-loop.js time ruby19 -wIlib bin/ambervm -lecma -o examples/simple-loop.js
The first implementation was of course nowhere near a complete interpreter, but I think it shows a lower bound for what can be done with OST based interpreters in Ruby.
The goal of the second implementation was automatic compiling using RACC. The results were wonderful; the resulting OST is very nice. The implementation is not complete; it doesn't handle scope, functions, and uses Ruby objects directly.
The third implementation is an improved version, using container objects and handling scope and functions. It is under development; it performs slower than the previous versions, but I expect it to stay like that, even with scope and functions added.
The fourth implementation uses some nice tricks to speed up this specific benchmark.
The fifth implementation runs all the specs. The sixth implementation runs two simple ECMA benchmarks.
The seventh version has fixes and performance tweaks.
The eighth version eliminated some illegal optimizations; now, for each += or -= a new Number core object is created. I hope to get the original optimization back, but for now, the focus is on correctness.
Result¶
Currently, ECMA_Fuku is about 10x faster than the latest version of ECMA.
I run three simple benchmarks:- simple_loop
- access-nsieve
- math-partial-sums