Featured in
Architecture & Design

Mini-talks: The Machine Intelligence Landscape: A Venture Capital Perspective by David Beyer. The future of global, trustless transactions on the largest graph: blockchain by Olaf Carlson-Wee. Algorithms for Anti-Money Laundering by Richard Minerich.

Featured in
Operations & Infrastructure

Mini-talks: The Machine Intelligence Landscape: A Venture Capital Perspective by David Beyer. The future of global, trustless transactions on the largest graph: blockchain by Olaf Carlson-Wee. Algorithms for Anti-Money Laundering by Richard Minerich.

Featured in
Enterprise Architecture

Mini-talks: The Machine Intelligence Landscape: A Venture Capital Perspective by David Beyer. The future of global, trustless transactions on the largest graph: blockchain by Olaf Carlson-Wee. Algorithms for Anti-Money Laundering by Richard Minerich.

Using JRuby to generate Code for the JVM

Even though JRuby has approached the performance of CRuby, sometimes that's still not fast enough. Users of CRuby can use Ryan Davis' RubyInline library with built-in support for C/C++ to easily generate Ruby C extensions. Charles Nutter from JRuby has now implemented a RubyInline builder for JRuby, allowing on the fly compilation of embedded Java code.

A drawback of the RubyInline for JRuby variant is the requirement of a Java 6 JDK (for the compiler), which might not yet be available on all systems.

Another way to get fast executing code is to generate the JVM bytecode directly. While this might sound like overkill for normal applications, code generating tools like compilers definitely benefit from a simple bytecode generation DSL, like the one Charles Nutter blogged about some time ago. But even with a DSL to write bytecode, this isn't a task for the faint of heart. An example from Charles' blog: the generation of a method called bar that adds the lower case version of the String-argument to the passed ArrayList.

A new addition to this field, also by Charles Nutter, is a new language called Duby that implements a subset of Ruby's syntax, enriched with some type inference logic (more on this on Charles' blog) that compiles to very fast bytecode. The same method to calculate the factorial, this time written for the Duby compiler:

class Fac def self.fac(max) {max => :int, :return => :int} i = max result = 1 while i > 1 result *= i i -= 1 end result endend

It's a prototype that shows the possibilities of type inference in a Ruby-like language, rather than a new language for programmers to use. It could also be used as a way for JRuby programmers to avoid having to fall back to Java for performance-critical paths, or to implement parts of JRuby itself, similar to Squeak Smalltalk's Slang, a subset of the Smalltalk language that can be easily translated to C. Rubinius has plans to use a similar approach called Garnet (InfoQ already talked to Evan Phoenix about Cuby/Garnet).