Hacker News new | ask | show | jobs
by brightball 2583 days ago
Rails is slow. Ruby isn’t slow.

Ruby has the same thing that every other language has, call outs to C code under the hood for most of the real work.

What makes Rails slow is the process around so much object creation and destruction, but this is exclusive to Rails itself.

You put a Sidekiq worker up against a Go worker for some background processing and the performance is comparable.

3 comments

> Ruby has the same thing that every other language has, call outs to C code under the hood for most of the real work.

Yes, this is exactly the problem. Ruby is so slow that you end up writing C extensions when you want to do any non-trivial computation. The documentation is bad, the tooling is bad, the build/CI complications are bad, and there's not much community info online about the process. And now your RoR developers have to support a C library, where a segfault can kill an entire Ruby interpreter.

I don't think most RoR apps run into these problems, which is why RoR is such a great thing in the first place, but we shouldn't brush aside how slow it is, and the implications of that when it becomes a problem.

> Ruby is so slow that you end up writing C extensions when you want to do any non-trivial computation. The documentation is bad, the tooling is bad, the build/CI complications are bad, and there's not much community info online about the process.

Perhaps for a classic C extension that's true, but (for portability across Ruby interpreters and other reasons), using FFI is usually the preferred way to do new C interop, and none of that is true for FFI.

Don’t get me wrong, there are faster languages out there.

The trade off that Ruby has always made was maximizing developer productivity. It’s never tried to be the fastest, but it’s plenty fast enough.

> And now your RoR developers have to support a C library

In Python you can write your low level extensions directly in Rust via PyO3 [0]. I guess there is something similar for Ruby.

[0]: https://github.com/PyO3/PyO3

When Rails came out, Ruby was the slowest language by far because its interpreter literally just walked an AST. No intermediate byte code, no VM, it just eval'd an AST. This reputation stuck longer though, although yeah I imagine Ruby is still slower than Python and Node even now despite having a VM.
Current stable version Ruby 2.6.2 with --jit is actually faster than Python 3 according to this: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
And actually slower also.
When the JIT really gets rolling mainstream, it could help quite a bit. Performance (3x over v2) is a primary goal of Ruby 3.

https://developers.redhat.com/blog/2018/03/22/ruby-3x3-perfo...

Ruby _is_ itself slow by any meaningful metric. That being said, the productivity gains usually outweigh the slowness.

I've been doing Elixir/Phoenix lately and subjectively it feels significantly faster than Ruby/Rails.