Projects That Are Making Fast Ruby a Reality
sitepoint.com
sitepoint.com
In the not-so-distant-past, one of the reasons why a good number of developers/projects announced they were moving away from Ruby and using other languages/compilers was due to Ruby's slow performance—and not just that Ruby was slow, but that Ruby was slow due to the actual nature of the language. In other words, Ruby was destined to always be slow, so it didn't make sense to invest in making Ruby faster because that's, to a certain extent, a fool's errand.
Now we're actually seeing a number of initiatives that are claiming to take Ruby into performance arenas that are an order of magnitude faster than before. And not just the compiler level, but all through the stack: faster app servers, faster libraries, faster frameworks, etc.
So that's all very exciting, and I'm super thrilled as a Ruby developer, but here's my question: if Ruby can actually be a relatively fast language, what was going on before? Were the "Ruby will always be slow" people simply wrong? Or are there some new breakthroughs in compiler design that make it much more feasible for such a dynamic language as Ruby to be more performant? Inquiring minds want to know!
http://blog.headius.com/2012/11/refining-ruby.html
It looks like JRuby has refinements now but maybe not great support for them (based on just some quick Googling):
https://github.com/jruby/jruby/issues/1062
So I'm curious if anything tested in the article has refinements support.
Personally I'm still skeptical of refinements, but I guess JRuby will have to support them or more and more gems will start to break.
So ruby either needed to piggy back on someone else's work (jvm or whatever) or get some next-level-smart vm developers. Even then, people have written about how ruby presents some serious challenges.
Arguably one of the most prevalent Java platforms these days, Android, doesn't JIT... it compiles AoT. Java is actually a great example of languages with static type systems being easier to optimize, whereas the JVM is the new hotness for everything dynamic.
Java's main usage (outside of Android) atm is on the server-side, and startup time isn't a huge deal there and you care about cost more than actual perf.
A small outsourced team in Denmark did, actually. Sure, they were hired by Google, but that kind of belies your argument that only a large corp can do this, no?
But who is going to finance them rebuilding the whole approach from scratch over several years, in a way that benefits a whole platform rather than just their company, and shelter the team from short-term priorities and reorgs?
That takes a big company that has an enormous economic stake in the entire platform.
But there's a lot of daylight between what you call "fast" and "pretty fast". For all the effort that has been poured into Javascript, it remains a slow language for general-purpose programming. That's why asm.js could speed up JS as much as it could; if JS was already "C fast" nobody would have needed or used asm.js. And nobody would talk about Web Assembly if JS was already that fast.
It is definitely true that the bytecode interpreters that pretty much all the dynamic languages started with were not the last words in speed, and things like JITs and such have sped them up a lot. When the dynamic interpreted languages were routinely 50x slower than C, there was room for improvement. But there seems to be a wall at around 10x slower than C for general-purpose programming [1] that the languages are having a hard time penetrating from what I can see: http://benchmarksgame.alioth.debian.org/u64q/which-programs-... (Bizarrely, they've broken out into two graphs, with the slower languages getting graphed first. It's actually one big graph, I think.)
Having heard people say for many, many years that "languages don't have speeds, only implementations do", I no longer believe that. After vast quantities of time and effort have been poured into the dynamic languages, they're still slow. Just not as slow as they used to be, and often with significantly larger memory footprints to get to "not as slow as they used to be".
NB: Pity LuaJIT is no longer on that site. If you design your "dynamic" language for speed, you can do a lot better. But I've not seen proof you can design a language for convenience and dynamicness and then come along 15+ years later and make it C-fast.
[1]: I have to qualify that, because any JIT worth its salt can optimize certain very advantageous code down to C speed. As the benchmark contains some of these tasks, you can see the dynamic languages with decent JITs reach their tails down to near C-speed in that graph. However, being able to optimize code that loops over integers and adds them up to C speed or even beyond if you automatically use SIMD doesn't mean that you're going to C performance in general.
In Ruby's case, ObjectSpace is worth taking a peek at for an example: http://ruby-doc.org/core-2.3.0/ObjectSpace.html We have here a method that counts all objects, by type, in the entire heap. How, exactly, could one propose to parallelize that? Not Easily. Does that leak synchronization needs -- and thus performance implications -- into every layer of GC, scheduling, class/module definition loading, and so on? Yup.
Doesn't matter how much you approach the pinnacle of excellence in JIT. Some definitions of operational parameters are just going to be expensive. Other languages that simply don't allow such operations are at a permanent advantage. There is no such thing as engineering without tradeoffs.
How wide is your phone? :-)
(It's just to confuse people who insist on saying this language is first, this language is second … as though rank order was useful information.)
http://benchmarksgame.alioth.debian.org/u32/which-programs-a...
And Mike Pall made Lua pretty damn fast.
... Ruby is still slow.
Sure, there are band-aids to assist with that stuff (Guard, Zeus, etc.), but you're still dealing with spaghetti-dependency, mutating-global-state, side-effecting hell.
Which is exactly why I now want to work with Elixir and Phoenix instead.
Note: It IS possible to write Ruby in such a way that almost none of this stuff actually comes to pass. But even if you do, you'll have to deal with an entire library of code that does not.
MAth is tricky in pure Ruby for example, the spec does a check on integers to make sure they can ben contained in what we'll call Int, and don't need to be transformed into BigInt. Ruby does this check every time an integer changes, which is wildly expensive, but super convenient. Its really nice for small N, but you shouldn't add n-dimensional arrays this way.
Also, run time meta-programming is pretty slow, especially if you lean on #method_missing, that's hard to fix.
Those two things aside, there aren't any reasons that Ruby can't be made much faster, in fact for many use cases JRuby is presently very fast and with Java interop you can leverage Java libs.
Simple answer, yes. Not saying that Ruby is fast now, however Ruby doesn't necessarily always have to be slow. Just like any languages/framework/etc. It can be made faster, although the amount of work to get there may be substantial.
At the time ruby was really slow, and with no real progress and a waning number of groups working to improve it. Now, it appears people are making progress and working on it.
I think that "if" still is a pretty big if. If Truffle/Graal ships and is able to run Rails at a 30x perf improvement, that would be huge. Right now there's still some work left there, and the original article notes that they haven't been able to replicate the claimed perf gains. What's also tricky is that while there can often be "performance sweet spots" [1] in dynamic languages, it's very easy to accidentally fall out of them and make most of your app slow even if theoretically it's possible for it to run faster.
The TechEmpower benchmarks [2] are pretty damning when it comes to Ruby's current performance relative to other languages. For some projects, eventually it's easier to switch to a different language that's already fast rather than investing into speeding up a slow one.
[1] http://mrale.ph/blog/2011/11/05/the-trap-of-the-performance-... [2] https://www.techempower.com/benchmarks/
While it is slightly unfair, most within the Ruby on Rails Community do not care about speed at all.
PHP has Facebook, Java has Sun and other Enterprise, JS has Google V8, as well as Mozilla / Apple providing competition, Lua has Mike Pall. Basically all these Dynamic Langauges has had million of dollars / man hours working on it for a long time.
In Ruby? If it wasn't for ko1 YARV Ruby is still very slow here.
So why all of a sudden we have two solution here that offer a magnitude of speed increase? My guess is that it created an interest within the Academic, VM Research Community, if they have to prove their VM ( OMR / Graal ) to work, they will have to choose one of the hardest, yet to optimized language to work on. I guess that is why both effort happens to be on Ruby.
Apparently, "the new builds are click-through licensed" and will be based off "Oracle's JDK rather than Open JDK."
I can't wait for Oracle to die.
commit: https://github.com/rbenv/ruby-build/commit/ca0e1474fcf3e2025...
pull request: https://github.com/rbenv/ruby-build/pull/864
Secondly, Oracle funded all of this work! Don't you think that's a little ungrateful? How relevant do you think faster Ruby even is to Oracle's core business? Less relevant than fast JS is to Google certainly, and yet, not only have they been funding a large cutting-edge research effort for years ... they gave the results away as open source too.
Sometimes I think people have lost perspective. I remember programming for Windows in the 1990s, when you were expected to pay for even basic things like treeview widgets or networking libraries. Now you get full blown JIT compilers for dynamic languages for nothing and people complain :(
It's not as crazy as it may seem and JRuby benefits hugely from it: http://chrisseaton.com/rubytruffle/cext/
real 0m3.843s user 0m11.867s ```
There is an AOT mode being worked on that should solve that, but it's not open source.