Wednesday, April 9, 2008

Ruby love in the browser

I'd heard of HotRuby before but thought it was merely a browser-based Ruby interpreter written in JavaScript. A second look at it, via John Resig's post yesterday brought this to the fore:

  1. Script finds <script type="text/ruby"></script> tags and extracts the inline Ruby code from them.

  2. The Ruby code is sent to the server via an XMLHttpRequest.

  3. The server-side CGI script (in Ruby, using Ruby 1.9) compiles the incoming Ruby into its associated opcodes and serializes it into a JSON data structure.

  4. The browser consumes the opcodes, translating it into JavaScript, and executes it.

Interesting, and according to John's post, this round-about approach still shows pretty impressive performance benchmarks.

To look at it from another perspective, we can also do browser-based Ruby with Silverlight, in the upcoming version 2 anyway. This would be managed Ruby code running on Silverlight's DLR, all on the (plugin-enabled) browser, without the round-trip that the HotRuby approach requires. I wonder how the performance benchmarks for such an approach, and how it stacks up against HotRuby.

0 comments: