25

JIT and Ruby's MJIT

 4 years ago
source link: http://engineering.appfolio.com/appfolio-engineering/2019/7/18/jit-and-rubys-mjit
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

If you already know lots about JIT in general and Ruby’s MJIT in particular… you may not learn much new in this post. But in case you wonder “what is JIT?” or “what is MJIT?” or “what’s different about Ruby’s JIT?” or perhaps “why in the world did they decide to do THAT?”…

Well then, perhaps I can help explain!

Assisting me in this matter will be Arthur Rackham , famed early-twentieth-century children’s illustrator whose works are now in the public domain . This whole post is adapted from slides to a talk I gave at Southeast Ruby in 2018.

I will frequently refer to TruffleRuby , which is one of the most complex and powerful Ruby implementations. That’s not because you should necessarily use it, but because it’s a great example of Ruby with a powerful and complicated JIT implementation.

What is JIT?

Do you already know about interpreted languages versus compiled languages? In a compiled language , before you run the program you’re writing, you run the compiler on it to turn it into a native application. Then you run that. In an interpreted language , the interpreter reads your source code and runs it more directly without converting it.

A compiled language takes a lot of time to do the conversion… once. But afterward, a native application is usually much faster than an interpreted application. The compiler can perform various optimizations where it recognizes that there is an easier or better way to do some operation than the straightforward one and the native code winds up better than the interpreted code - but it takes time for the compiler to analyze the code and perform the optimization.

A language with JIT (“Just In Time” compilation) is a hybrid of compiled and interpreted languages. It begins by running interpreted, but then notices which pieces of your program are called many times. Then it compiles just those specific parts in order to optimize them.

The idea is that if you have used a particular method many times, you’ll probably use it again many times. So it’s worth the time and trouble to compile that method.

A JITted language avoids the slow compilation step, just like interpreted languages do. But they (eventually) get the faster performance for the parts of your program that are used the most, like a compiled language.

Does JIT Work?

In general, JIT can be a very effective method. How effective depends on what language you’re compiling and what features of that language - you’ll see numbers from 6% to 40% or even more in JavaScript , for instance.

And in fact, there’s an outdated blog post by Benoit Daloze about how TruffleRuby (with JIT) can run a particular CPU-heavy benchmark at 900% the speed of standard CRuby , largely because of its much better JIT (see graph below.) I say “outdated” because TruffleRuby is likely to be even faster now… though so is the latest CRuby.


Recommend

  • 4
    • blog.pyston.org 3 years ago
    • Cache

    baseline jit and inline caches

    baseline jit and inline caches Creating an implementation for a dynamic language using just in time compilation (JIT) techniques involves a lot of compromises mainly between complexity of the implementation, speed, warm-up tim...

  • 8

    Rhizome - a JIT for Ruby, implemented in pure Ruby Rhizome is a paedagogical just-in-time compiler (JIT) for Ruby, implemented in pure Ruby. It's not really designed to be used. It's designed to show you how JITs work and why perhaps...

  • 3

    Rob and Jason are joined by Hal Finkel from the US Department of Energy. They first talk to Hal about the LLVM 13 release and why the release notes were lacking. Then they talk to Hal about his C++ JIT Proposal, the Clang prototype and how i...

  • 2

    Ruby 将引入新 JIT 编译器:YJIT,平均速度提升 23%近日,Ruby 代码仓库新增了一个关于合并 YJIT 的PR。据介绍,YJIT 是一种使用 Lazy Basic Block Versioning (LBBV) 编译器架构构...

  • 14
    • blogs.igalia.com 2 years ago
    • Cache

    Adding record and tuple support to the JIT

    Adding record and tuple support to the JIT Today I started working on implementing the Record and Tuples proposal for JavaScript in the JIT in SpiderMonkey....

  • 3
    • developer.squareup.com 2 years ago
    • Cache

    Ruby’s New JIT

    Ruby’s New JITRuby is about to get Way FasterCRuby just got a JIT! There have been many attempts at implementing a JIT for CRuby, the reference implementation of Ruby. None have been merged, until now...

  • 2

    JIT Compilers for Ruby and Rails: An Overview

  • 8

    Ruby 再引入另外一套 JIT 實做:RJIT 在 Hacker News Daily 上看到「

  • 2
    • www.marcobehler.com 1 year ago
    • Cache

    Understanding GraalVM, AOT & JIT

    You can use this guide to understand what GraalVM is, how it works and how Just-In-Time (JIT) compilation compares to Ahead-Of-Time (AOT) compilation). Intro I was lat...

  • 2
    • www.infoworld.com 11 months ago
    • Cache

    Ruby previews pure Ruby JIT compiler

    Ruby previews pure Ruby JIT compiler Ruby 3.3.0 brings significant performance improvements to YJIT and previews RJIT, an experimental just-in-time compi...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK