Co-Lead Developer Charles Nutter on JRuby: A High-Performance Implementation of the Ruby Programming Language for the JVM

Charles Nutter On Jruby

TL; DR: JRuby, released in 2001, empowers users to reap the benefits of the Java Virtual Machine (JVM), including high-performance, real threading, and a vast array of libraries. The open-source tool serves as a fast and accurate implementation of Ruby while providing robust new features such as parallelism, concurrency without a global interpreter lock (GIL), and close integration with the Java language. Moving forward, the JRuby community will remain focused on ensuring compatibility with Ruby and pursuing more aggressive optimization.

Ruby was initially developed in the 1990s by Yukihiro Matsumoto, who named the open-source computing language after the birthstone of one of his colleagues. Since then, the object-oriented language has become increasingly popular, with new versions typically released on Christmas day as a gift to programmers.

But despite its robust features and strong community, Ruby does have its limitations. That’s where JRuby — a stable, high-performance, fully threaded implementation of the Ruby programming languages for the Java Virtual Machine (JVM) — comes in.

“We’re the next step for the high end-traffic users when an application gets to a point where regular Ruby is not scaling up well enough,” said Charles Oliver Nutter, Co-Lead Developer of JRuby.

JRuby logo

JRuby is an open-source implementation of the Ruby language for Java Virtual Machine (JVM).

The free, open-source software is released under a three-part EPL/GPL/LGPL license and is similar to the Ruby interpreter but written in Java. Therefore, it serves as a fast and accurate implementation of Ruby while providing robust new features such as parallelism, concurrency without a global interpreter lock (GIL), and close integration with the Java language.

Like Ruby, JRuby includes object-oriented programming and dynamic typing. But it is also tightly integrated with Java, empowering users to reap the benefits of JVM, including high performance, real threading, and a vast array of libraries.

In terms of frameworks, JRuby supports RSpec, Rake, and RubyGems. JRuby has also been able to run the Ruby on Rails web framework since the May 2006 release of version 0.9. Red Hat, a leading provider of enterprise open source solutions, has sponsored work on JRuby since 2012. Moving forward, the JRuby community will remain focused on ensuring compatibility with Ruby and pursuing more aggressive optimization.

Enabling Stable, Fully Threaded Java Implementation Atop the JVM

JRuby’s co-lead developers are Charles and Thomas Enebo, but past developers, including Ola Bini and Nick Sieger, also contributed to the software. It was initially released 19 years ago in 2001.

“In JRuby’s early days, when the first commits started coming in, there was mostly interest in getting Ruby tooling on the JVM,” Charles said. “So they started with the parser and whatnot but then rapidly moved toward very basic Ruby implementation.”

When Charles joined in 2005, the team attempted to run the libraries and applications that people used in the Ruby community — such as package installers. “About a year later, we actually managed to get Ruby to run the Ruby on Rails web framework. That was an exciting moment; it was when we realized we could actually make JRuby a useful tool for folks.”

Over the last 15 or so years, the JRuby community has witnessed massive shifts in the JRuby and Java development space.

“The arrival of Rails in 2004 changed the way applications get up and running,” Charles said. “Now, pretty much every framework has at least sensible defaults. Most of them have application generators, whereas before, you had to do a lot of hand configuration.”

Charles said that though it’s difficult to quantify the adoption rate of JRuby specifically, the team has seen thousands of users over the years, some of whom use JRuby on extensive applications, such as banking sites and election results sites for the BBC.

“We’ve never tried to be a replacement for regular Ruby,” Charles said. “If Ruby is scaling well enough for you, if that tool works for your application, then maybe that’s as good as it needs to be for you. JRuby is the choice of a smaller percentage of the folks out there, but that still means tens of thousands of apps.”

Tapping into the Benefits of the JVM Environment

Charles told us that JRuby’s main advantages come from using Ruby on a JVM. Essentially, this capability gives Ruby access to anything that can run on a JVM, including code in other languages.

Putting the Ruby programming language atop the JVM allows developers to build, package, and distribute applications to end users on multiple platforms.

“The return on investment is the same as what you’d get going to a JVM,” Charles said. “It’s Ruby first but with all of the capabilities of the Java platform behind it.”

JRuby can be used to access powerful JVM features, including libraries.

With JRuby, developers can use both Ruby and Java libraries. They can also access the Java garbage collection feature, a memory management tool that finds and deletes unused objects to free up space, and the JVM just-in-time (JIT) compiler, which compiles bytecode into native code at run time to improve performance.

Once developers are ready to get started with the platform-independent language, they’ll experience easy installation and migrations, with few hassles.

Ensuring Compatibility with the Standard Ruby

When it comes to internal development, the JRuby community focuses primarily on two concerns, the most urgent of which is maintaining compatibility with the standard Ruby programming language.

“That means handling user reports when there’s some edge case of a feature that we don’t support,” Charles said. “It requires looking at the new version of Ruby each year, making sure that we have all the same changes to our implementation, and making sure we match feature for feature.”

The latest version of JRuby, 9.2.x, is compatible with Ruby 2.5.x and stays in sync with C Ruby. Charles told us these compatibility issues take up about 75% of development time.

“The remaining 25% of the time is spent focused on users of the Java platform; whether they’re trying to integrate it with other Java libraries or into an enterprise stack, we’re making sure that works,” he said. “We’re also leveraging the JVM itself better: Doing a better job of optimizing code, reducing allocation, making sure that we’re being good JVM citizens so we can pass all those benefits on to Ruby users.”

Up Next: Pursuing More Aggressive Optimization

Charles told us that in the last two years or so, JRuby’s developers made great strides in terms of Ruby compatibility.

“Every time a new Ruby version comes out, we’re only a step behind,” he said. “It’s maybe another month’s worth of work to catch up all the features, and that’s started to free up a lot more time to look at aggressive optimizations and more advanced ways of compiling Ruby code down to JVM bytecode.”

That means the team can spend about half of its time on compatibility and the other half on performance.

“Over the next year, I think we’re going to start seeing performance gains in areas we didn’t have time to spend on before,” he said.