RubyFlux – Statically Compile Ruby to Java

Charles Nutter, creator of JRuby, has a new offering for the Ruby/Java community: RubyFlux (formerly called fastruby). RubyFlux is a static Ruby to Java compiler. It uses JRuby to analyze the AST of the Ruby files and generate Java source files. The generated code has no run-time dependencies and ends up being pure Java.

RubyFlux could be an amazing tool if/when it gets built into a usable state. It provides massive speedups over MRI or even JRuby.
 
 
 
 
 
Here’s a preliminary benchmark. It generates a Mandelbrot Set ten times to compare the native Ruby to the much faster RubyFlux. Here are my results:

LanguageLast Run TookTotal (Real) Time
Ruby0.776 sec7.798 sec
JRuby0.259 sec3.964 sec
RubyFlux0.044 sec0.756 sec

Ruby took almost 8 seconds, and RubyFlux took less than a tenth of a second! It’s just pure Java code running.

RubyFlux will make your Ruby code able to run on any JVM without any run-time dependencies. So, what’s the catch? It’s not ready, and there will be limitations when it is. The project exists mostly as a tech demo or function proof-of-concept; it has a long way to go before it will be production ready. It does not have a working test suite and is missing large pieces of Ruby functionality, including supports for blocks. There’s also no mechanism for calling into existing Java libraries, but Nutter says that’s next on the list.

When finished, RubyFlux will be a subset of Ruby in the same way that RubyMotion is. Some of the most dynamic pieces of Ruby may not be there.

It’s not done yet, but RubyFlux shows great promise in getting serious Ruby development in places like Android or embedded applications. With some work, it could be the Android equivalent to RubyMotion.

TL;DR

RubyFlux statically compiles Ruby into Java. It has awesome performance and runs everywhere Java does with no runtime dependencies, but it isn’t done yet.
 

Reference: RubyFlux – Statically Compile Ruby to Java from our JCG partner Shawn Anderson at the Atomic Spin blog.

Share and enjoy!


© 2010-2012 Java Code Geeks. Licenced under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.