I haven't kept up with the evolving Ruby implementation internals, so I will sure as heck buy this new version of the book.
I'll have to pick up a copy of this "Ruby Under a Microscope" book when the new version comes out. I've always liked Ruby, I just haven't had much chance to use it.
At first glance this seems too simple. Compare it to JavaScript JITs, which IIRC can compile hot spots even in functions that are only called a few times (e.g. those that contain heavy loops) via on-stack replacement. (Although I’ve also heard on-stack replacement called a “party trick” - more useful for optimising benchmark scores than for real code.)
But on the other hand, Ruby’s language design might help here. Idiomatic Ruby uses blocks for loop bodies - so can Ruby JITs optimise long-running loops by treating the loop body as just another function?
And by what process is the correct compiled block used depending on the input variable types?
Yes that's something I want to dig into and explore in this chapter... when exactly does Ruby's JIT compiler activate and optimize our code? And you're right: since Ruby will JIT blocks as if they were separate function many loops will be optimized using this simple heuristic.
This sounds like Microsoft when they moved from VB6 to VB.Net. At least they have a good thing going with C# though.
VB6 was quite an interesting beast. You could do basically everything that you could do in languages like C/C++, but in most cases, you could churn out code quicker. This even extended to DirectX/Direct3D! For Web pages? ASP Classic.
The tl;dr is that I really wish that ease of development were prioritized along with everything else. One of the reasons I like Ruby is the elegance of the language and ease of using it.
Note that I've been using it since the mid 2000s or so, but not exclusively (both it and VB6 defined my career, however). C# is my second most favorite.
If Ruby had the GUI design tools VB6 had, it would be interesting to look at the popularity stats
Anyway, I'm rambling, so there is that. ;)
This basic algorithm is called "Basic Block Versioning." Maxime Chevalier-Boisvert from Shopify has some great presentations online about this; for example [1].
I believe ZJIT, the newer JIT engine, uses a different approach. I'm exploring that now.
[1] https://www.youtube.com/watch?v=zO9_uTaELCw — RubyConf 2021 - YJIT - Building a new JIT Compiler inside CRuby by Maxime Chevalier Boisvert.
https://sorbet.org/blog/2021/07/30/open-sourcing-sorbet-comp...
So it's "fast". There's plenty more that can be done to make it much faster still, but even before yjit, MRI had gotten pretty decent.
> You could do basically everything that you could do in languages like C/C++
As long as there is some form of memory access, any language can do basically everything that one can do in C/C++, but this doesn't make much sense.
No VB6 had really easy COM integration which let you tap into a lot of Windows system components. The same code in C++ often required hundreds of lines of scaffolding, and I'm not exaggerating
I did recent testing that showed it to be faster than Python but slower than Lua: Lua, Ruby and Python ran my benchmark in 12, 18 and 25 seconds respectively.
This was measured using the latest versions of each language (5.4, 3.4 and 3.13), using only the interpreters, no JITs.
> I haven't used it in about 10 years
It looks like the relative performance of the three languages hasn't changed much since I did a similar benchmark with Ruby 2.0, about that long ago.
Compared to itself from 10 years ago I think it's made great progress. Can't put a number to it but I wouldn't be surprised if it's 2x or 3x faster, especially with the "new" JIT (YJIT) enabled. The JIT comes with a memory usage penalty though. You can see some benchmarks over time (although not going back as far as 10 years) at https://speed.ruby-lang.org
1: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
I do agree it'd be interesting to have a GUI designer for Ruby. Does QML paired with QtRuby work?
In the distant past I had a book about FXRuby, but never used it much, and don't think it had a UI designer - it was just bindings to Fox Toolkit, which is lightweight, but not as well maintained as Qt or Gtk.
I dropped OSX long ago, so can't even try it out any more.
I wonder how much of the LLVM bits could be reused? I'm sure LLVM's changed a bunch in the last 15 years, too.
You might get destroyed for this? Why?
I don’t know what either of those mean in this context, and I used VB6 for a couple years at least and have been programming ObjC and / or Swift since 2006, with some time in Rails over a couple years.
I’m extremely confused by your comment, it’s apparently near verboten in polite company, yet, manages to say nothing other than that while invoking several things of which I’m quite familiar.
If you are destroyed, I anticipate it will be for a quarter baked, horrible, analogy between ObjC/Swift (or is it Ruby/Swift)? and VB6/VB.NET that somehow has something to do with Ruby.
0 - https://www.goodreads.com/book/show/624316.Enterprise_Integr...
AOT compiling Ruby is hard. I'm trying [1] [2].
Sorbet would be in a good position because part of the challenge of making it fast is that Ruby has a lot of semantics that are rarely used but that makes making compiled Ruby fast really hard. E.g. the bignum promotion adds overhead to every single operation unless you can prove invariants about the range of the values; the meta-programming likewise adds overhead and makes even very basic operations really expensive unless you can prove classes (or individual objects) aren't being mucked with...
So starting with type checking is an interesting approach to potentially allow for compiling guarded type-specific fast paths. If my compiler ever gets close enough to feature complete (it's a hobby project, so depends entirely on how much time I get, though now I also justify more time for it by using it as a test-bed for LLM tooling), it's certainly a direction I'd love to eventually explore.
[1] https://hokstad.com/compiler (not updated for a decade)
[2] https://github.com/vidarh/writing-a-compiler-in-ruby/ (updated now primarily by Claude Code; it's currently focusing on actually passing RubySpec and making speedy progress, at the cost of allowing some fairly ugly code - I do cleanup passes occasionally, but most of the cleanup will be deferred until more passes)
Now what .NET never did as good as VB 6, was ease of COM development experience.
Which given the role of COM in Windows APIs since Vista, is a major pain point as I don't get if COM is so relevant, why Microsoft teams keep rebooting, badly, the COM development experience.
For some reason, there are vocal teams at Microsoft that resist anything in C++ that is comparable to VB, Delphi, .NET, C++ Builder ease of use regarding COM.
Hence why we got MFC COM, ATL COM, WRL, WinRT (as COM evolution), C++/CX, C++/WinRT, WIL, and eventually all of them lose traction with that vocal group that aparently rather use COM with bare bones IDL files, using the command line and VI on Windows most likely.
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
https://bell-sw.com/announcements/2022/06/28/hotspot-vs-open...
https://eclipse.dev/openj9/performance/ (non-impartial source, of course)