Hacker News new | ask | show | jobs
by jhoechtl 1704 days ago
How many Jit compiler attempts did we already see? It seems to me there has never been substantial progress towards speed or is it just that other languages implementations increase speedwise at the same pace?

Source: Computer Languages Shootout

2 comments

How many? Quite a lot, actually, I personally can count at least 10 attempts at JIT-ing Ruby.

The are 2 main reasons for that.

1. For a good decade - from ~2005 to ~2015 - Ruby was among the most often used tech stacks at startups, and any performance work on Ruby (of which two major fronts were GC and JIT compilation) were perceived as extremely impactful and attractive.

2. Ruby is actually one of the most if not the most dynamic and complex programming languages out there and thus is one of the most challenging to build a runtime for and optimize. It became a de-facto benchmark for JIT research (among the more conventional Java). Over the years many vendors invested into Ruby compilers to push their underlying VM technology. Microsoft sponsored IronRuby to improve their .NET runtime, Sun sponsored JRuby and Oracle sponsors TruffleRuby.

As for progress, the biggest roadblock to Ruby JITs adoption has always being Rails. Rails uses a lot of Ruby features and pushes the language pretty far. Thus, you can't run Rails without your Ruby implementation being very complete and very MRI-compatible (MRI is the default Ruby implementation).

Plus, Rails uses Ruby in a way that is defeats virtually all best practices to produce a JIT-friendly code. Thus, there's no JIT compiler that offers any performance improvements for Rails apps - and in truth there might not be one ever. In fact, YJIT is exciting because it's the first JIT-compiler that seems to offer some speedups for at least a fey Rails benchmarks. People follow it closely, because these speedups might be a fluke, and as the compiler becomes more compliant, they may disappear (that happened in past with some JITs).

Other people tackle this problem by switching away from Rails to other frameworks. AFAIK Stripe themselves don't use Rails in most of their code, so they might benefit a lot from this work even without big improvements for common Ruby benchmarks (language shootout, Techempower, Discource benchmarks).

> People follow it closely, because these speedups might be a fluke, and as the compiler becomes more compliant, they may disappear (that happened in past with some JITs).

They're not. YJIT is really 100% compatible with regular interpreter MRI and already run a small % of production traffic at Shopify as well as fully pass the gigantic test suite of Shopify's 10+ years old monolith as well as GitHub's test suite.

This is not a fluke, that's what you get by building a JIT directly inside MRI rather than starting from scratch. It's harder and slower, but you get full compatibility from day 1.

Oh, I'm sure know that. YJIT is such a marvel of a technology!

I'm so happy for Maxime Chevalier-Boisvert to have such a resounding success with her JIT research after so many years!

    Rails uses Ruby in a way that is defeats virtually 
    all best practices to produce a JIT-friendly code.
I've seen this mentioned a lot, and certainly the history of compiled Ruby + Rails benchmarks indicates this is true.

However, I've never quite understood -- why exactly is this the case?

Is it just the sheer size of Rails? Or is it (ab)using Ruby in weird ways?

edit:

This is the more or less definitive answer, I guess, though it's a bit over my head!

https://k0kubun.medium.com/ruby-3-jit-can-make-rails-faster-...

There have been at least 16 attempts to write a compiler for Ruby!

I’m giving a talk about the history of compiling Ruby at RubyConf.

Wow! I'll try to count.

- 2 Rubinius attempts (Gnu Lightning and LLVM)

- MacRuby

- JRuby (do you count InDy separately?)

- IronRuby (do you count DLR separately? They didn't start with DLR, as far as I recall)

- MagLev - I think they hoped to GemStone would JIT user's Ruby code with bits of interpreter.

- TruffleRuby

- RubyOMR

- Vladimir's MJIT

- Koichi's MJIT

- YJIT

Do we count HotRuby and Opal? - both compile to JS.

I miss a few.

EDIT: mRuby, duh

A few AOT attempts as well, including mine (I've hardly touched mine in the last couple of years, but I have a bunch of GC improvements that haven't been pushed to GitHub that brings it close to self-compiling, but still huge gaps - e.g. no float or regex support, no exceptions)
Adding a few more:

- DragonRuby - I don't know if it should count separately form MacRuby

- There were at least 5 Ruby-to-JavaScript compilers I remember from about 10 years ago, but they are very hard to find. Surprisingly, one of them - ruby2js - is still alive and actively developed!

DragonRuby's just mRuby scripting a framework written in C.
RubyMotion, the compiler created after MacRuby's creator left Apple.
Could you provide some online resources available on that topic?