Is Ruby 3 Actually Three Times Faster? (2024)

Is Ruby 3 Actually Three Times Faster? (1)

Ruby 3x3 announced that Ruby 3.0 would be three times as fast as Ruby 2.0. It was an audacious goal, especially for a language released in 1995.

Ruby 3 is due to be released in less than a month. They’re hard at work on some of the features, but non-JIT performance is pretty close to release speed. If they pull another 5%-10% speed increase at the last minute (which happened for Ruby 2.5!) it’ll be surprising. The current performance is basically the “real” Ruby 3 performance.

So… Did it happen? Is Ruby 3 really three times the speed?

The answer is a little complicated, but overall it’s “yes.”

Now: let’s hit the real answer and the details. That’s the fun part.

Who’s This Guy?

Why listen to me? Well, I wrote one of the two official Ruby 3 benchmarks. I worked for AppFolio on Ruby 3 for about three years. I keep track of this stuff pretty closely. But mostly I’ll be linking to other posts I wrote for AppFolio and on FastRuby and maybe elsewhere. They all have open source code. Feel free to check me!

What’s Performance, Exactly?

A language doesn’t have one speed. When somebody says “language X is 2.5 times as fast as language Y,” that’s always an approximation. All languages run “sleep” at exactly the same speed, and two of them may use the exact same regexp library. But maybe variable assignment is way faster in one language than another, while the second language is better at optimising away stack variables.

In other words, performance is a million little things that are faster… or they’re slower or they’re the same. We take an average and hand-wave. That’s okay. It’s how humans deal with complicated things.

Benchmarks are all lies because of this. Little operations make for dramatic benchmarks, and big operations make (if you’re lucky) representative “workload benchmarks.” We can’t make a benchmark not lie. We can only pick our favourite lie.

What’s Our Favourite Lie?

Here are two favourite lies, embodied by my benchmark (Rails Ruby Bench) and Mame-san’s benchmark, OptCarrot.

One favourite lie is this: Ruby performance means Rails performance. How is Ruby 3’s Rails performance?

It turns out it hasn’t changed significantly since Ruby 2.6. It also turns out it got far better from Ruby 2.0 to 2.6.

We don’t know the exact final performance of Ruby 3.0. Watch for a benchmark from me in January! But it’s going to look a lot like Ruby 2.6 and Ruby 2.7.

And that means a large Rails app’s performance has increased by over 70% since Ruby 2.0.

Let’s be clear: that’s a lot.

That’s total end-to-end performance to handle HTTP requests in parallel. It uses the same exact Ruby code with the same exact SQL queries, attached to Redis and Postgres and real service with a real big open-source Rails app that people actually use.

In other words, the Ruby part of that performance has increased by a lot more than 70%, because everything that isn’t Ruby is the exact same in my tests.

A lot of a Rails app isn’t Ruby time. It’s waiting for the database. It’s waiting for the disk. The web server is serving static files. A Rails app does a lot of non-Ruby stuff, and it should.

A Rails app wasn’t going to triple in speed. It’s doing too much non-Ruby stuff. Realistically, the Ruby part hasn’t tripled in speed. I don’t have exact numbers, but it would be fair to estimate around 2.5x. It would be very hard to get an accurate only-the-Ruby-parts number, for all kinds of good reasons.

Still, 2.5x is very, very good. Ruby 3.0 will have a big jump in Rails performance, but most people are already using it.

Ractors (a new Ruby 3 concurrency primitive) will also pave the way for later speedups if Rails takes advantage of them. Like threads, it’ll take time and changes to the framework. And right now, Ractors’ performance is underwhelming. But they’re also a not-yet-released new feature, so there’s a lot of room to improve.

Our Other Favourite Lie

Other than Rails performance, what matters?

One other answer is “straight-line CPU performance on a CPU-intensive benchmark.” And for that we’ll turn to OptCarrot, an excellent Ruby 3 benchmark. It runs a headless Nintendo (NES) emulator as fast as it can, which is a fun way to measure.

Rails didn’t benefit from Ruby’s new-ish opt-in JIT system. MJIT is a complicated beast with interesting trade-offs. If you turn it on then Rails Ruby Bench gets slower, not faster.

But OptCarrot is exactly what MJIT was designed for and it does really well with it.

Ruby 3.0 recently hit 3x Ruby 2.0’s performance with JIT. We’re there. Assuming they can keep performance that good for the actual release, Ruby 3.0 manages 3x the frames that Ruby 2.0 did.

The answer, then, is a straightforward “yes.”

Note that JIT does not “make Ruby three times faster.” It’s that Ruby 3.0, which is already a lot faster than Ruby 2.0, is three times as fast as Ruby 2.0 with JIT turned on. It’s fast without JIT, but not a full three times the speed of Ruby 2.0.

Make sense?

What’s the Score, Then?

It’s been nearly eight years since Ruby 2.0. There have been a lot of performance changes. The generational garbage collection in Ruby 2.4 is hugely faster than the much simpler 2.0 GC. BootSnap has made bootup in Rails far faster. If you remember back to Ruby 1.8.7 in 2008, Ruby has more-than-doubled in speed to Ruby 2.0, and then tripled again for Ruby 3.0. The OptCarrot results are more like 10x from Ruby 1.8.7 to Ruby 3. A 10x speedup in 10 years? Not bad for a language that just turned 25.

It’s been a long trip. And that’s without going into the other two parts of Ruby 3 — concurrency and type safety, both of which are separate major efforts.

Is Ruby 3 really three times the speed of eight-years-ago Ruby? Day-to-day, yes, it absolutely is. The Rails speedup is more like double than triple in practice since a lot of Rails time isn’t Ruby. But double isn’t bad! And CPU-intensive code is now solidly three times the speed.

You can judge the concurrency and type-safety of Ruby 3 for yourself. But I’m going to call the performance goal a solid success.

Sure, we have to wait a month. Ruby 3 will actually be released on 25th December of 2020. But all the signs are good.

You can also play with Ruby 3.0.0-preview1 right now, and I’m sure there will be at least one more before the final release.

You Hunger to Get Better

Subscribe to get free ebook chapters and an emailed coding class now, plus videos and articles a few times a month.

Why this specific newsletter? You want to be an expert. Expertise comes from learning the fundamentals, deeply. And that comes from the best kind of practice. I write with that in mind. I won't waste your time.

(Yes, I also sell things. They're good, but I'm fine if you don't buy them.)

comments powered by Disqus

Read Next

How Do I Increase Testing of My Codebase?

ruby rails

Computer Science: Just the Useful Bits

ruby rails

What Can You Do with Rack Middleware?

rack rails rebuildingrails

An Interview with Collin Jilbert on Job Hunting for Junior Developers

video career

Is Ruby 3 Actually Three Times Faster? (2024)

FAQs

Is Ruby 3 Actually Three Times Faster? ›

The answer, then, is a straightforward “yes.” Note that JIT does not “make Ruby three times faster.” It's that Ruby 3.0, which is already a lot faster than Ruby 2.0, is three times as fast as Ruby 2.0 with JIT turned on. It's fast without JIT, but not a full three times the speed of Ruby 2.0. Make sense?

Is Ruby 3 faster? ›

Ruby 3.0 without JIT is factor 1.2 faster than Ruby 2.1. 0; Ruby 3.0 with JIT is only factor 1.4 faster than Ruby 2.1. 0. Crystal is about factor 20 faster.

What are the advantages of Ruby 3? ›

Conclusion. Ruby 3.3 brings performance improvements in many areas: faster and less frequent garbage collection, memory optimizations, faster code, and YJIT improvements. And the best part is that, in most applications, these performance improvements will be noticeable without any modification of the code!

What is the difference between Ruby 2 and 3? ›

It's faster. Increasing speed was one of the key goals behind 3.0., and by all accounts it went well. In fact, the stated goal was to make it “three times” faster than 2.0. A couple of caveats: 2.0 was quite a while ago, and there were a lot of performance gains between there and 2.7.

Is Ruby still slow? ›

It is slower than some other languages some of the time depending on what you are using it for. However, Ruby has a rich ecosystem of libraries (gems) many of which either provide highly optimised Ruby code or include native extensions that run almost as fast as coding in a different language.

Is Ruby faster than go? ›

Development Speed

Golang doesn't need to be interpreted, so it is a faster programming language than Ruby.

Is Python or Ruby faster? ›

Ruby: Ruby is an interpreted language, which generally has a higher runtime compared to compiled languages. Python: Python has better runtime performance than Ruby but still falls behind Go. Go: Go is a statically-typed, compiled language with strong performance characteristics, resulting in the fastest runtime.

What is the disadvantage of Ruby? ›

This results in flexibility losses because there are many configured set objects that can not be modified by developers. This is one of the biggest disadvantages of Ruby, as it doesn't allow the developers to make required core changes and necessitates a shift to other tech stacks.

What changed in Ruby 3? ›

The Ruby update promises to change this. With Ruby 3, programmers will be able to use parallel threaded computation. That means that Ruby now is single-flow language. With Ruby 3.0, it will be possible to execute parallel tasks, which makes the whole process way faster.

Why is Ruby so awesome? ›

The code in Ruby is easy to read like English text. Ruby is very powerful with its syntax, but it can be a bit harder for newcomers, unlike languages with simpler syntax such as Python.

Is Ruby 3 backwards compatible? ›

ruby3-backwards-compatibility. This gem provides a compatibility layer to Ruby 3 projects that still have legacy code written against Ruby 2's stdlib. Only use this if you upgrade to Ruby 3 but still depend on some third-party code that breaks on Ruby 3.

When did Ruby 2.3 come out? ›

Ruby releases by version number
Release VersionRelease DateRelease Notes
Ruby 2.1.92016-03-30more...
Ruby 2.3.02015-12-25more...
Ruby 2.2.42015-12-16more...
Ruby 2.1.82015-12-16more...
118 more rows

When was Ruby 3.1 released? ›

Ruby 3.1. Version 3.1. 0 was released on Christmas of 2021. It included an autocomplete feature.

Is Ruby 3 fast? ›

Speed improvements

Ruby 3.0 is 3 times faster than Ruby 2!

Why is Ruby not popular anymore? ›

Ruby on Rails has been criticized for insufficient scalability compared to other frameworks, primarily due to its limited support for concurrency and asynchronous processing. Our insight: It's important to understand that the scalability of an application isn't solely determined by the framework itself.

Is Ruby becoming obsolete? ›

People have been saying Ruby is dead or certainly on its way out for several years now, but most such claims are made about prior evolutions of Ruby rather than the version we are working with today – which is far from dying and is in fact evolving.

What is the fastest Ruby compiler? ›

Regarding performance, TruffleRuby is by far the fastest Ruby implementation on the yjit-bench benchmark suite which includes railsbench , etc. To achieve this performance TruffleRuby needs a fair amount of warmup, as other advanced JIT compilers do. If you find any performance issue, please see this guide.

Is Ruby a 3 level laser? ›

Ruby is a three-level laser. Fig. 7.13 shows a rough sketch of the optical transitions of the ruby laser. In this laser, optical pump radiation from a flashlamp (xenon in pulsed operation) between 400 and 600 nm is absorbed by the Cr+3 ions, exciting carriers into the 4F2 band.

Is Ruby 3 backwards compatible with Ruby 2? ›

ruby3-backwards-compatibility. This gem provides a compatibility layer to Ruby 3 projects that still have legacy code written against Ruby 2's stdlib. Only use this if you upgrade to Ruby 3 but still depend on some third-party code that breaks on Ruby 3.

Is Ruby Sapphire a Gen 3? ›

The third generation (generation III) of the Pokémon franchise features 135 fictional species of creatures introduced to the core video game series in the 2002 Game Boy Advance games Pokémon Ruby and Sapphire.

Top Articles
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 5457

Rating: 4.6 / 5 (76 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.