Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

HotRuby: A JavaScript & Flash Virtual Machine That Runs Ruby

By Peter Cooper / March 26, 2008

hotruby.png

HotRuby is a JavaScript and Flash powered virtual machine that can run Ruby code compiled to opcode by YARV.

You can write Ruby script within a Web page within <script type="text/ruby"> .. </script> tags, and HotRuby will then extract it, send it to be compiled by a remote script, and then return it for the JavaScript and Flash powered virtual machine to display within the page. There are lots of demos, including a physics Flash application (as seen in the screenshot above), a very curious pinball game, and a benchmarking script (which shows HotRuby as being 78% faster than Ruby 1.9 on my machine?)

There's also a live "do it yourself" coding environment if you want to give it a test by writing some code of your own.

Comments

  1. Charles says:

    wow.

    !!!

    I've gotta say that blew me away. Pretty remarkable stuff, even for an initial prototype. Incredibly, on my computer, this implementation of a YARV VM in javascript (using firefox 2 btw, which isn't the fastest) was faster than my ruby 1.8 and 1.9.

  2. Michael Neumann says:

    Change the "+=" into "<<" and Ruby is again 100 times faster :)

    For a comparison of RubyJS vs. HotRuby take a look here:
    http://www.ntecs.de/blog/articles/2008/03/26/rubyjs-vs-hotruby

    Nevertheless, great stuff!

  3. Alan Brown says:

    I'm afraid I've wrecked the physics demo. The chain came of the the little tractor thingy and I can't get it back on!

    This cannot be a page of code to write. That's insane! And brilliant.

    Another page of code for the tractor repair shop.

  4. AW says:

    Awesomeness.

    But, I can't get the pinball game to stop "freezing."

    Well, it's better than having my entire browser freeze though...

  5. Daniel says:

    That's amazing. Considering the gains we can get with small additions to it, I can see how a lot of people could contribute to fill the gaps.

  6. Soleone says:

    Very nice idea!

    On my machine it takes 6.90 seconds in the Browser using HotRuby and 6.61 seconds if I run the benchmark-code in a local script under Windows.

  7. CptOatmeal says:

    Something is very fishy about these speed results. I need to do some more digging, but I think this apparent speed disparity has to do with differing garbage collection/memory schemes.

    The code:
    50000.times{|e| sum += e.to_s}

    will create a HUGE number of new string objects laying around the heap (string concatenation creates new strings.)

    A simple fibonacci function yields very different results:

    def fib(n)
    return n if n == 0 or n == 1
    fib(n-1)+fib(n-2)
    end

    On my Ruby 1.8.6 this took 0.019 seconds.
    HotRuby took 2.911 seconds.

Other Posts to Enjoy

Twitter Mentions