We're hiring!

We're actively seeking designers and developers for all three of our locations.

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:

Language Last Run Took Total (Real) Time
Ruby 0.776 sec 7.798 sec
JRuby 0.259 sec 3.964 sec
RubyFlux 0.044 sec 0.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.

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.
 

Shawn Anderson (37 Posts)

Maker at Atomic Object. Lover of Ruby. Hobbyist game developer.

This entry was posted in Ruby and tagged , , . Bookmark the permalink. Both comments and trackbacks are currently closed.

9 Comments

  1. Posted January 7, 2013 at 5:20 pm

    Github link is now https://github.com/headius/rubyflux , not https://github.com/headius/fastruby

    Nice article! I always like to hear about innovation in the Ruby community.

    • Shawn Anderson
      Posted January 8, 2013 at 9:34 am

      Thanks Andrew. The rename was in-progress when I wrote this. The link has been updated.

  2. Posted January 8, 2013 at 9:26 am

    There already is a RubyMotion for Android (sort of): http://ruboto.org/

    Not completely the same scope, but a nice project.

    • Shawn Anderson
      Posted January 8, 2013 at 9:38 am

      Marc,
      You’re right, Ruboto does allow for ruby to run on Android. However it has some fundamental differences. Ruboto uses JRuby to interpret your Ruby code and has a hefty overhead of both startup and runtime performance. RubyFlux, on the other hand, statically compiles your ruby code ahead of time into pure Java. That means no runtime dependencies, no start-up overhead, and pure Java performance.

      • Posted January 8, 2013 at 9:44 am

        That’s why I said “sort of” :)

        But you are right of course: Once RubyFlux gets full access to the (Andoid) Java-API, it can really become an interesting alternative, especially for heavy load apps.

  3. Daniel
    Posted January 10, 2013 at 11:20 am

    TL;DR – I love this section, but I have to wonder why it isn’t written first? (it is after all simply an abstract)

    • Pedro
      Posted January 11, 2013 at 2:58 pm

      It’s a great article, except at that, which I agree with you. TL;DRs should be at the top. It doesn’t mean the article won’t be read. Actually it can captivate the reader the same was an introduction or caption does.

      • Shawn Anderson
        Posted January 11, 2013 at 3:15 pm

        The TL;DR has now moved to its proper place at the top of the article. Thanks for the feeback.

  4. Posted January 16, 2013 at 7:27 pm

    There is a mailing list now, if anyone is interested: https://groups.google.com/forum/?fromgroups#!forum/ruby_flux