Live data from Hacker News

Why Is JRuby Slow?

earthly.dev

41–50 of 64 posts

Re: Why Is JRuby Slow?

#41
post #22
post #15

Earlier quoted context omitted.

Crystal isn't the "only option" for fast Ruby because it's not Ruby. If Crystal is an option, so are a lot of languages.

It is the option when syntax familiarity and similar language concepts count.

Crystal is little like Ruby now.

Re: Why Is JRuby Slow?

#42
post #13

Seems like there's obviously a big I/O performance difference. Maybe it's something simple like buffering being setup differently or not at all or sync vs async. It'd be interesting to dig in more Even something like mmap can drastically improve performance since it lets the kernel handle I/O asynchronously from your program execution (so your code doesn't block as much or as easily on I/O)

We don't know that it's really I/O, as in "pushing some bytes to the system". All we know is that the author saw a hot method called "write" and stopped the analysis there. It might well be something like messing around with character encodings to get those bytes in the first place.

Re: Why Is JRuby Slow?

#43
post #24

Here's the summary: Ruby like most of all other Linux applications from that age was written to run in multi-process mode for parallelism, instead of being multi threaded. But running multi-process is heavy on the JVM as it has to load the virtual machine and JIT for every process start, special when the processes are short lived. Java solves it by encouraging running things as multi-threaded instead of multi-process…

> Here's the summary: [...] But running multi-process is heavy on the JVM as it has to load the virtual machine and JIT for every process start, special when the processes are short lived.

This is a valid summary of some facts, but not of the article or facts relevant to the article. Some quotes:

"Jekyll is not forking processes, so that is not the issue."

"The area where JRuby and TruffleRuby shine are long running processes that have had time to warm up. Based on suggestions I put together a repo of a simple small Jekyll build being built 20 times by the same process in a repo here. After 20 builds with the same running process the build times do start to converge, but even after that MRI Ruby is still fastest."

Re: Why Is JRuby Slow?

#44
post #9

Earlier quoted context omitted.

Could you not make the same argument about JavaScript? JavaScript was pretty slow for many years. Google then put some significant engineering investment into the V8 engine, resulting in a huge increase in JavaScript's performance.

There's significantly more motivation to run JS faster since JS isn't a choice; if you need an interactive website, it will use JS. Ruby is a choice.

I guess everyone with significant investment in ruby codebases can just "choose" to rewrite everything in another language.

Whilst they are doing their multiyear rewrites, it would be nice if someone could optimise the ruby runtime a bit for them.

Re: Why Is JRuby Slow?

#45
So there was no easy way to get a profile from the JVM version, and data came only from looking at the CRuby profiles where file access dominates. Then an informed guess: slower JVM file access.

This process and lack of data in itself sounds like a receipe for performance problems in the JVM version, unless there was some low probabvility coincidence that prevented getting the profile data only in this case. Good measurements are a prerequisite for sustainable and maintainable performance work.

Re: Why Is JRuby Slow?

#46
My impression is that interest in JRuby has gradually declined, in favor of CRuby (MRI).

I guess both because CRuby has gotten a lot faster, and because in practice any difference is easily paved over with extra hardware (which is cheap).

Re: Why Is JRuby Slow?

#47
post #45

So there was no easy way to get a profile from the JVM version, and data came only from looking at the CRuby profiles where file access dominates. Then an informed guess: slower JVM file access. This process and lack of data in itself sounds like a receipe for performance problems in the JVM version, unless there was some low probabvility coincidence that prevented getting the profile data only in this case. Good mea…

There was (is?) a time, where JRuby couldnt pass the ruby spec because of their IO abstraction written in Java. They changed that code to be written in ruby instead, with FFI to call out to libc, which made it more correct but slower, afaik.

Re: Why Is JRuby Slow?

#48
post #24

Here's the summary: Ruby like most of all other Linux applications from that age was written to run in multi-process mode for parallelism, instead of being multi threaded. But running multi-process is heavy on the JVM as it has to load the virtual machine and JIT for every process start, special when the processes are short lived. Java solves it by encouraging running things as multi-threaded instead of multi-process…

The way Android solved this problem (before they implemented AOT) was to fork the JVM post-load (and I think even JIT) of all the core Java and Android classes; the real somewhat-fundamental problem with the JVM in a multi-process system isn't really having to "load the virtual machine and JIT for every process start" but the multiple, almost-certainly-uncoordinated garbage collectors.

http://www.cydiasubstrate.com/id/727f62ed-69d3-4956-86b2-bc0...

Re: Why Is JRuby Slow?

#49
post #6

If you want fast Ruby it seems Crystal is your only option. Ruby is an interpreted language released in 1996 for scripting. Why are we surprised when attempts to shoe-horn it into something else (Ruby 3.0, JRuby, Truffle Ruby) fall flat?

Ruby's basically as fast as Node.js. If you look at comparative benchmarks, Roda/Rack/Puma is within spitting distance of Koa, Fastify, etc. Express is actually slower in some benchmarks. I don't think a lot of people are aware of just how much faster the Ruby ecosystem has gotten in the past few years (especially when you leave Rails out of the equation which is known not to do well in microbenchmarks).

Interested in these benchmarks. Could you specify?

Re: Why Is JRuby Slow?

#50

There's once I was running some jruby stuff in jenkins during a build, the job kept on hanging on some stage, I thought there must be bug somewhere, I forced kill it a couple of times with no success, but kept the last one running before I head home. Then after a couple of hours, I found out an email said the built was passed... eventually, I had figured out that jruby was using /dev/random, since jenkins was running…

You can pass "-Djava.security.egd=/dev/urandom" to the JVM instead of changing the mounts.
Post reply on HN