Some nights you just can't stop hacking.

C:\JRubyWork\jruby-svn>jruby test_fib_compiler.rb
Time for interpreted: 56.311
Time for compiled: 31.636
(these times are significantly slower than the others because I'm on my laptop tonight)

fib is very call-intensive, obviously, and the double recursion doesn't help when our method call overhead is still so high. Compilation definitely gains us a lot, but there's more optimization to be done and lots more work on cleaning up the call path. With a tail-callable fib we'd also be able to eliminate almost all the recursion overhead, as well. This is a very early result.

Make no mistake, however...this is a working fib compiler. It handles if, local var lookups, calls, and fcalls (implicit receiver); it mostly ignores newlines; and it partially supports def. When the compiler is instantiated it creates a class to hold code it encounters. Currently def nodes are the only way to initiate creating a method, but as you can see from the test script it does actually create a Java "fib_java" method that accepts appropriate arguments for our reflection-based callback. That method is then hooked up to a callback, and bound to "fib_java" in Kernel (that's obviously a little hacky, but the eventual logic of binding to the appropriate module or class is a ways off).

There's many improvements to be made to this, and it obviously only supports a very few nodes. It's a good foundation, however.

--
Charles Oliver Nutter @ headius.blogspot.com
JRuby Developer @ www.jruby.org
Application Architect @ www.ventera.com

Attachment: test_fib_compiler.rb
Description: application/ruby

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jruby-devel mailing list
Jruby-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jruby-devel

Reply via email to