# jRuby better than MRI?

**URL:** <https://www.ruby-forum.com/t/jruby-better-than-mri/210921>\
**Category:** JRuby\
**Created:** [August 20, 2011, 7:28pm UTC](https://www.ruby-forum.com/t/jruby-better-than-mri/210921 "2011-08-20T19:28:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [August 20, 2011, 7:28pm UTC](https://www.ruby-forum.com/t/jruby-better-than-mri/210921/1 "2011-08-20T19:28:15Z")

</div>

I have a rails project that runs on MRI 1.9.2 implementation.

1. MRI is implements Ruby in C. And JRuby implements Ruby specification  
in  
Java. If C is faster than java, it means MRI is faster than JRuby. Am I  
Right?
2. Also, regarding memory leaks, MRI leaks memory a lot. It takes my  
server  
box’s memory very quickly. Does replacing MRI with JRuby in the server  
help?

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [August 20, 2011, 7:36pm UTC](https://www.ruby-forum.com/t/jruby-better-than-mri/210921/2 "2011-08-20T19:36:18Z")

</div>

Hello there! Answers below.

On Sat, Aug 20, 2011 at 12:27 PM, Anand M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a rails project that runs on MRI 1.9.2 implementation.
> 
> 1. MRI is implements Ruby in C. And JRuby implements Ruby specification in  
> Java. If C is faster than java, it means MRI is faster than JRuby. Am I  
> Right?

C is often faster than Java, but not by a great deal. JRuby’s core  
classes, written in Java, often outperform MRI’s C code because of  
better memory management and the JVM’s excellent optimizing JIT  
compilers.

In general, Ruby code should run faster on JRuby, since JRuby compiles  
Ruby code to JVM bytecode, and the JVM compiles that bytecode to  
native machine code, while MRI always interprets. Ruby core classes  
may or may not be faster on JRuby depending on how well we’ve  
written/optimized them compared to MRI, but in most cases they should  
be faster too. So JRuby should be faster than MRI (faster than 1.8.7  
for sure, faster than 1.9.2 most of the time).

> 1. Also, regarding memory leaks, MRI leaks memory a lot. It takes my server  
> box’s memory very quickly. Does replacing MRI with JRuby in the server help?

If it’s actually a leak stemming from MRI itself, then switching to  
JRuby would fix it. If it’s a third-party library that’s leaking, then  
it could either be a problem with the library (in which case switching  
to JRuby wouldn’t help) or a problem with how MRI runs the library  
(where JRuby would theoretically run it better).

If you decide to attempt a move to JRuby, let us know! We like to help  
and hear about successful migrations 🙂

- Charlie

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [August 20, 2011, 7:45pm UTC](https://www.ruby-forum.com/t/jruby-better-than-mri/210921/3 "2011-08-20T19:45:37Z")

</div>

ok … now I understand why JRuby will give me more performance.

I would like to move my project to JRuby. But there is a C extension I  
use -  
gbarcode, for generating barcodes. If there is a ruby alternative to  
that  
and all the other dependent gems work well in JRuby, I will switch.

Although I will try JRuby first in staging server for sometime 🙂

On Sat, Aug 20, 2011 at 11:05 PM, Charles Oliver N.  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [August 20, 2011, 7:50pm UTC](https://www.ruby-forum.com/t/jruby-better-than-mri/210921/4 "2011-08-20T19:50:33Z")

</div>

2011/8/20 Anand M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> 1. MRI is implements Ruby in C. And JRuby implements Ruby specification in  
> Java. If C is faster than java, it means MRI is faster than JRuby. Am I  
> Right?

Code execution speed depends on many factors and JVM can optimize and  
deoptimize it at runtime. This sometimes yields better performance than  
static C compilers can get (but usually only for long running  
processes).

One of the biggest factors in Ruby Web application performance is  
garbage  
collection time. To put it politely, MRI garbage collector is known to  
be  
mediocre. JVM has multiple garbage collectors to choose from and some of  
them are really advanced and tunable.

Instead of guessing, profile your application on both implementations  
and  
see for yourself (and do not just profile for 10 seconds, try 5-10  
minutes).

> 1. Also, regarding memory leaks, MRI leaks memory a lot. It takes my server  
> box’s memory very quickly. Does replacing MRI with JRuby in the server help?

What you are seeing is likely to be the infamous behavior of MRI to not  
release memory it once allocated, to avoid allocation performance  
effect.

## JRuby will certainly be better in this regard.

MK

> **[michaelklishin - Overview](https://github.com/michaelklishin)**
>
> Infrastructure, data services, distributed systems, Erlang, Elixir, Rust - michaelklishin

[http://twitter.com/michaelklishin](http://twitter.com/michaelklishin)

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [August 20, 2011, 7:51pm UTC](https://www.ruby-forum.com/t/jruby-better-than-mri/210921/5 "2011-08-20T19:51:10Z")

</div>

On Sat, Aug 20, 2011 at 6:44 PM, Anand M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ok .. now I understand why JRuby will give me more performance.  
> I would like to move my project to JRuby. But there is a C extension I use -  
> gbarcode, for generating barcodes. If there is a ruby alternative to that  
> and all the other dependent gems work well in JRuby, I will switch.

Try barby: [GitHub - toretore/barby: The Ruby barcode generator · GitHub](https://github.com/toretore/barby)

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [August 20, 2011, 7:52pm UTC](https://www.ruby-forum.com/t/jruby-better-than-mri/210921/6 "2011-08-20T19:52:24Z")

</div>

On Sat, Aug 20, 2011 at 12:50 PM, aslak hellesoy  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Try barby: [GitHub - toretore/barby: The Ruby barcode generator · GitHub](https://github.com/toretore/barby)

Nice, hadn’t seen that one. Death to C extensions!

- Charlie

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [August 20, 2011, 8:07pm UTC](https://www.ruby-forum.com/t/jruby-better-than-mri/210921/7 "2011-08-20T20:07:51Z")

</div>

thanks, I will checkout barby if it can replace good old gbarcode.

Anand  
[http://www.rubyinair.com](http://www.rubyinair.com)

On Sat, Aug 20, 2011 at 11:20 PM, aslak hellesoy

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [August 20, 2011, 8:09pm UTC](https://www.ruby-forum.com/t/jruby-better-than-mri/210921/8 "2011-08-20T20:09:05Z")

</div>

ok, I will profile my app and see if JRuby will work for me.

On Sat, Aug 20, 2011 at 11:19 PM, Michael K. \<

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [September 1, 2011, 9:19am UTC](https://www.ruby-forum.com/t/jruby-better-than-mri/210921/9 "2011-09-01T09:19:46Z")

</div>

On 20 August 2011 20:08, Anand M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ok, I will profile my app and see if JRuby will work for me.

let us know.
