SlideShare uma empresa Scribd logo
1 de 25
Ruby JIT compilation
gain speed with (little) pain
Special thanks to
Amoniac OÜ
for all your support
<3
About me
● Mykhailo Bortnyk
● Language researcher
○ working with Ruby, C, JavaScript, Erlang
○ #3 contributor of mruby/c
● Co-creator of Kottans
○ lecturer from very beginning till 2016
○ currently community is self-driving
● Social media
○ github: @vessi
○ twitter: @mikhailbortnyk
○ facebook: @vessimir
● What is JIT
● Known Ruby JIT implementations
● Demo time
● Future of JIT in Ruby
Presentation plan
What is JIT
What is JIT
“JIT compilation compiles a piece of application code at runtime into binary
machine code, then allows the VM to execute the generated code directly rather
than interpret the original piece of application code. It is like treating the entire
piece of application code as a single super instruction”.
Xiao-Feng Li, “Advanced Design and Implementation of Virtual Machines”
What is JIT
JIT, just-in-time compilation, in other words dynamic translation - technology
to improve bytecode systems (in fact, almost every interpreter).
Actually, it just compiles some methods, blocks or regions to machine code to
speed up performance of bytecode execution.
Used in: Java, some JavaScript implementations, .NET framework, PyPy Python.
Also exists in PHP (HipHop), SmallTalk (GemStone), Perl.
JIT use case
● Well, interpreters are slow
● So, step 1: compile strings of code to bytecode
● Still slow
● Step 2: compile some bytecode to machine code
● Now better
● Step 3: drop your language and write your software in C
● Err… let’s better stop on step 2
● PROFIT!
JIT (very) short history
● Very first and very naïve JIT implementation by McCarthy for LISP in 1960
● Second JIT implementation by Ken Thompson for QED regular expressions in
1968
● Milestones:
○ Mitchell, 1970, language LC^2
○ Sun Microsystems, 1983, Smalltalk. Self VM was only 2x slower than plain C
○ James Gosling, 1993, Java. Invented term Just-in-time
○ Michael Franz, 1994, Oberon. Dissertation “Code Generation on-the-fly: a key to portable
software”
○ RubyMotion team, 2012, Ruby on LLVM (translation to Objective C)
○ Maglev team, 2011, Ruby on Smalltalk GemStone VM (by VMWare)
○ Takashi Kokubun, 2017, Ruby with LLVM binding
○ Vladimir Makarov, 2017, Ruby native JIT implementation
Types of JIT
JIT implementations in general can be grouped into 3 types:
● Method-based JIT (replaces original implementation in class VTable with
native function call)
● Trace-based JIT (only compiles code on specific execution path, path is
identified through profiling)
● Region-based JIT (hybrid between method- and trace-based
implementations)
How JIT loads native code
● Interpreter loads vtable
● Interpreter sends
bytecode to compiler
● Interpreter replaces
bytecode with native
call
Ruby JIT implementations
JRuby
JRuby was originally created in 2001 by Jan Petersen and was just one-to-one
port of Ruby 1.6 code. JIT was not implemented at this time.
From version JRuby 1.1 JIT support were added together with Ruby 1.8.7 support.
JIT compiles Ruby bytecode to JVM bytecode. Uses region-based JIT.
Able to work with GraalVM from version 9.x.x.x
● Needs warm up time
● Needs more memory
● Eliminates GIL
Rubinius
Created in 2009 by Evan Phoenix basing on “Blue Book” of Smalltalk-80. Uses
principle “implement most of Ruby in Ruby itself”.
JIT is method-based. Counts method calls and method hash (to expire JIT result
on method modification).
If method is called more than LIMIT times - adds it to JIT queue. JIT queue is
managed by background native thread which replaces bytecode of warm method
with call of native instructions.
Maglev Ruby
Maglev is alternative Ruby implementation created in 2008 on top of GemStone/S
Smalltalk virtual machine by GemTalk company.
Targeted Ruby 1.8.7, had one-to-one Ruby/Smalltalk thread mapping, shared VM
state storage and SmallTalk JIT from GemStone VM (trace-based JIT AFAIK,
can’t check, GemStone/S is dead).
Project is dead (last commit 2 years ago, active development stopped in 2015).
deoptimization branch by Shyohei Urabe
This branch contained first naïve implementation of JIT, used very few of JIT
optimizations, but uses less memory than full-power JIT implementation.
Submitted at 26 Aug 2016.
Not merged (and will not be).
Reference URL: https://github.com/ruby/ruby/pull/1419
MJIT by Vladimir Makarov
JIT implementation made by Vladimir Makarov, author of Ruby 2.4 hash tables
reimplementation, worker of RedHat.
Author held RubyKaigi keynote in 2017.
Converted YARV to register-based instead of stack-based (smaller instructions
but larger memory footprint). Built JIT on top of new VM implementation.
MJIT can reach 230% performance of Ruby 2.0.0 but is pretty unstable.
LLRB by Takashi Kokubun
Created by Takashi Kokubun. Inspired by earlier Evan Phoenix’s work.
Contains manually callable LLVM Ruby port.
Uses gem `llrb` as frontend to LLVM compiler, should be used with specially
patched version of Ruby 2.5 (actually, some C constants just made public
exportable).
Supports almost all YARV instructions.
github: https://github.com/k0kubun/llrb
MJIT-YARV by Takashi Kokubun
Based on Vladimir Makarov’s work, but without changing Ruby VM to register-
based. Several JIT optimizations were turned off.
These reverted changes made JIT slower but more stable.
Reference PR: https://github.com/ruby/ruby/pull/1782
Reference ticket: https://bugs.ruby-lang.org/issues/14235
Partially merged in trunk 10 days ago.
Able to run Rails stably.
Demo time
source at github://vessi/rm20.git
Future of JIT in Ruby
Well, it will just appear in 2.6 release.
You don’t need to wait to 3.0
Q&A time
Thanks!
My friends are looking for
normal Ruby developer
(not another me)

Mais conteúdo relacionado

Mais procurados

Venkat Subramaniam Building DSLs In Groovy
Venkat Subramaniam Building DSLs In GroovyVenkat Subramaniam Building DSLs In Groovy
Venkat Subramaniam Building DSLs In Groovy
deimos
 
Powerlang: a Vehicle for Lively Implementing Programming Languages
Powerlang: a Vehicle for Lively Implementing Programming LanguagesPowerlang: a Vehicle for Lively Implementing Programming Languages
Powerlang: a Vehicle for Lively Implementing Programming Languages
FAST
 
使用Eclipse快樂的mruby開發
使用Eclipse快樂的mruby開發使用Eclipse快樂的mruby開發
使用Eclipse快樂的mruby開發
yamanekko
 
Venkat Subramaniam Blending Java With Dynamic Languages
Venkat Subramaniam Blending Java With Dynamic LanguagesVenkat Subramaniam Blending Java With Dynamic Languages
Venkat Subramaniam Blending Java With Dynamic Languages
deimos
 
A Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVMA Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVM
Charles Anderson
 

Mais procurados (19)

Intoduction to Android Development
Intoduction to Android DevelopmentIntoduction to Android Development
Intoduction to Android Development
 
GraalVM - OpenSlava 2019-10-18
GraalVM - OpenSlava 2019-10-18GraalVM - OpenSlava 2019-10-18
GraalVM - OpenSlava 2019-10-18
 
Alternative approach to native Kotlin
Alternative approach to native KotlinAlternative approach to native Kotlin
Alternative approach to native Kotlin
 
Bootify Yyour App from Zero to Hero
Bootify Yyour App from Zero to HeroBootify Yyour App from Zero to Hero
Bootify Yyour App from Zero to Hero
 
Venkat Subramaniam Building DSLs In Groovy
Venkat Subramaniam Building DSLs In GroovyVenkat Subramaniam Building DSLs In Groovy
Venkat Subramaniam Building DSLs In Groovy
 
Powerlang: a Vehicle for Lively Implementing Programming Languages
Powerlang: a Vehicle for Lively Implementing Programming LanguagesPowerlang: a Vehicle for Lively Implementing Programming Languages
Powerlang: a Vehicle for Lively Implementing Programming Languages
 
PHP vs Node.js
PHP vs Node.jsPHP vs Node.js
PHP vs Node.js
 
使用Eclipse快樂的mruby開發
使用Eclipse快樂的mruby開發使用Eclipse快樂的mruby開發
使用Eclipse快樂的mruby開發
 
MacRuby For Ruby Developers
MacRuby For Ruby DevelopersMacRuby For Ruby Developers
MacRuby For Ruby Developers
 
Groovy android
Groovy androidGroovy android
Groovy android
 
Custom angular libraries
Custom angular librariesCustom angular libraries
Custom angular libraries
 
Stockholm JAM September 2018
Stockholm JAM September 2018Stockholm JAM September 2018
Stockholm JAM September 2018
 
Venkat Subramaniam Blending Java With Dynamic Languages
Venkat Subramaniam Blending Java With Dynamic LanguagesVenkat Subramaniam Blending Java With Dynamic Languages
Venkat Subramaniam Blending Java With Dynamic Languages
 
A Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVMA Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVM
 
BIO routing - a versatile, fast and reliable routing daemon in golang
BIO routing - a versatile, fast and reliable routing daemon in golangBIO routing - a versatile, fast and reliable routing daemon in golang
BIO routing - a versatile, fast and reliable routing daemon in golang
 
Free the Functions with Fn project!
Free the Functions with Fn project!Free the Functions with Fn project!
Free the Functions with Fn project!
 
Es build presentation
Es build presentationEs build presentation
Es build presentation
 
Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finesse
 
React web development
React web developmentReact web development
React web development
 

Semelhante a Ruby JIT Compilation

WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014
Minko3D
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
mfrancis
 
Dynamic Languages on the JVM
Dynamic Languages on the JVMDynamic Languages on the JVM
Dynamic Languages on the JVM
elliando dias
 

Semelhante a Ruby JIT Compilation (20)

JavaOne2015-What's in an Object?
JavaOne2015-What's in an Object?JavaOne2015-What's in an Object?
JavaOne2015-What's in an Object?
 
#JavaOne What's in an object?
#JavaOne What's in an object?#JavaOne What's in an object?
#JavaOne What's in an object?
 
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
Highly Surmountable Challenges in Ruby+OMR JIT CompilationHighly Surmountable Challenges in Ruby+OMR JIT Compilation
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
 
Micronaut: A new way to build microservices
Micronaut: A new way to build microservicesMicronaut: A new way to build microservices
Micronaut: A new way to build microservices
 
just in time JIT compiler
just in time JIT compilerjust in time JIT compiler
just in time JIT compiler
 
Concurrency in ruby
Concurrency in rubyConcurrency in ruby
Concurrency in ruby
 
Introduction to .net
Introduction to .netIntroduction to .net
Introduction to .net
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll build
 
WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014
 
Tutorial c#
Tutorial c#Tutorial c#
Tutorial c#
 
.Net introduction by Quontra Solutions
.Net introduction by Quontra Solutions.Net introduction by Quontra Solutions
.Net introduction by Quontra Solutions
 
Blazor v1.1
Blazor v1.1Blazor v1.1
Blazor v1.1
 
Gwt kickoff - Alberto Mancini & Francesca Tosi
Gwt kickoff - Alberto Mancini & Francesca TosiGwt kickoff - Alberto Mancini & Francesca Tosi
Gwt kickoff - Alberto Mancini & Francesca Tosi
 
WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...
WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...
WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...
 
Javascript as a target language - GWT KickOff - Part 2/2
Javascript as a target language - GWT KickOff - Part 2/2Javascript as a target language - GWT KickOff - Part 2/2
Javascript as a target language - GWT KickOff - Part 2/2
 
TechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance InteroperabilityTechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance Interoperability
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
 
Dynamic Languages on the JVM
Dynamic Languages on the JVMDynamic Languages on the JVM
Dynamic Languages on the JVM
 
Dalvik jit
Dalvik jitDalvik jit
Dalvik jit
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesBUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
 

Mais de Amoniac OÜ

Mais de Amoniac OÜ (15)

Dokku your own heroku 21
Dokku   your own heroku 21Dokku   your own heroku 21
Dokku your own heroku 21
 
GO in Heterogeneous Language Environments
GO in Heterogeneous Language EnvironmentsGO in Heterogeneous Language Environments
GO in Heterogeneous Language Environments
 
Cleaners of Caribbean
Cleaners of CaribbeanCleaners of Caribbean
Cleaners of Caribbean
 
Ambiguous Sinatra
Ambiguous SinatraAmbiguous Sinatra
Ambiguous Sinatra
 
Capistrano and SystemD
Capistrano and SystemDCapistrano and SystemD
Capistrano and SystemD
 
Distributed Cluster in Ruby
Distributed Cluster in RubyDistributed Cluster in Ruby
Distributed Cluster in Ruby
 
Roda: Putting the Fun Back into Ruby Web Development
Roda: Putting the Fun Back into Ruby Web DevelopmentRoda: Putting the Fun Back into Ruby Web Development
Roda: Putting the Fun Back into Ruby Web Development
 
Rubymotion: Overview and Ecosystem
Rubymotion: Overview and EcosystemRubymotion: Overview and Ecosystem
Rubymotion: Overview and Ecosystem
 
Rupher
RupherRupher
Rupher
 
Different Ways of Integrating React into Rails - Pros and Cons
Different Ways of Integrating React into Rails - Pros and ConsDifferent Ways of Integrating React into Rails - Pros and Cons
Different Ways of Integrating React into Rails - Pros and Cons
 
Functional Web Apps with WebMachine Framework
Functional Web Apps with WebMachine FrameworkFunctional Web Apps with WebMachine Framework
Functional Web Apps with WebMachine Framework
 
Functional Ruby
Functional RubyFunctional Ruby
Functional Ruby
 
How to Become a Сhef
How to Become a СhefHow to Become a Сhef
How to Become a Сhef
 
Let's Count Bytes! Launching Ruby in 32K of RAM
Let's Count Bytes! Launching Ruby in 32K of RAMLet's Count Bytes! Launching Ruby in 32K of RAM
Let's Count Bytes! Launching Ruby in 32K of RAM
 
Deployment tales
Deployment talesDeployment tales
Deployment tales
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Ruby JIT Compilation

  • 1. Ruby JIT compilation gain speed with (little) pain
  • 2. Special thanks to Amoniac OÜ for all your support <3
  • 3. About me ● Mykhailo Bortnyk ● Language researcher ○ working with Ruby, C, JavaScript, Erlang ○ #3 contributor of mruby/c ● Co-creator of Kottans ○ lecturer from very beginning till 2016 ○ currently community is self-driving ● Social media ○ github: @vessi ○ twitter: @mikhailbortnyk ○ facebook: @vessimir
  • 4. ● What is JIT ● Known Ruby JIT implementations ● Demo time ● Future of JIT in Ruby Presentation plan
  • 6. What is JIT “JIT compilation compiles a piece of application code at runtime into binary machine code, then allows the VM to execute the generated code directly rather than interpret the original piece of application code. It is like treating the entire piece of application code as a single super instruction”. Xiao-Feng Li, “Advanced Design and Implementation of Virtual Machines”
  • 7. What is JIT JIT, just-in-time compilation, in other words dynamic translation - technology to improve bytecode systems (in fact, almost every interpreter). Actually, it just compiles some methods, blocks or regions to machine code to speed up performance of bytecode execution. Used in: Java, some JavaScript implementations, .NET framework, PyPy Python. Also exists in PHP (HipHop), SmallTalk (GemStone), Perl.
  • 8. JIT use case ● Well, interpreters are slow ● So, step 1: compile strings of code to bytecode ● Still slow ● Step 2: compile some bytecode to machine code ● Now better ● Step 3: drop your language and write your software in C ● Err… let’s better stop on step 2 ● PROFIT!
  • 9. JIT (very) short history ● Very first and very naïve JIT implementation by McCarthy for LISP in 1960 ● Second JIT implementation by Ken Thompson for QED regular expressions in 1968 ● Milestones: ○ Mitchell, 1970, language LC^2 ○ Sun Microsystems, 1983, Smalltalk. Self VM was only 2x slower than plain C ○ James Gosling, 1993, Java. Invented term Just-in-time ○ Michael Franz, 1994, Oberon. Dissertation “Code Generation on-the-fly: a key to portable software” ○ RubyMotion team, 2012, Ruby on LLVM (translation to Objective C) ○ Maglev team, 2011, Ruby on Smalltalk GemStone VM (by VMWare) ○ Takashi Kokubun, 2017, Ruby with LLVM binding ○ Vladimir Makarov, 2017, Ruby native JIT implementation
  • 10. Types of JIT JIT implementations in general can be grouped into 3 types: ● Method-based JIT (replaces original implementation in class VTable with native function call) ● Trace-based JIT (only compiles code on specific execution path, path is identified through profiling) ● Region-based JIT (hybrid between method- and trace-based implementations)
  • 11. How JIT loads native code ● Interpreter loads vtable ● Interpreter sends bytecode to compiler ● Interpreter replaces bytecode with native call
  • 13. JRuby JRuby was originally created in 2001 by Jan Petersen and was just one-to-one port of Ruby 1.6 code. JIT was not implemented at this time. From version JRuby 1.1 JIT support were added together with Ruby 1.8.7 support. JIT compiles Ruby bytecode to JVM bytecode. Uses region-based JIT. Able to work with GraalVM from version 9.x.x.x ● Needs warm up time ● Needs more memory ● Eliminates GIL
  • 14. Rubinius Created in 2009 by Evan Phoenix basing on “Blue Book” of Smalltalk-80. Uses principle “implement most of Ruby in Ruby itself”. JIT is method-based. Counts method calls and method hash (to expire JIT result on method modification). If method is called more than LIMIT times - adds it to JIT queue. JIT queue is managed by background native thread which replaces bytecode of warm method with call of native instructions.
  • 15. Maglev Ruby Maglev is alternative Ruby implementation created in 2008 on top of GemStone/S Smalltalk virtual machine by GemTalk company. Targeted Ruby 1.8.7, had one-to-one Ruby/Smalltalk thread mapping, shared VM state storage and SmallTalk JIT from GemStone VM (trace-based JIT AFAIK, can’t check, GemStone/S is dead). Project is dead (last commit 2 years ago, active development stopped in 2015).
  • 16. deoptimization branch by Shyohei Urabe This branch contained first naïve implementation of JIT, used very few of JIT optimizations, but uses less memory than full-power JIT implementation. Submitted at 26 Aug 2016. Not merged (and will not be). Reference URL: https://github.com/ruby/ruby/pull/1419
  • 17. MJIT by Vladimir Makarov JIT implementation made by Vladimir Makarov, author of Ruby 2.4 hash tables reimplementation, worker of RedHat. Author held RubyKaigi keynote in 2017. Converted YARV to register-based instead of stack-based (smaller instructions but larger memory footprint). Built JIT on top of new VM implementation. MJIT can reach 230% performance of Ruby 2.0.0 but is pretty unstable.
  • 18. LLRB by Takashi Kokubun Created by Takashi Kokubun. Inspired by earlier Evan Phoenix’s work. Contains manually callable LLVM Ruby port. Uses gem `llrb` as frontend to LLVM compiler, should be used with specially patched version of Ruby 2.5 (actually, some C constants just made public exportable). Supports almost all YARV instructions. github: https://github.com/k0kubun/llrb
  • 19. MJIT-YARV by Takashi Kokubun Based on Vladimir Makarov’s work, but without changing Ruby VM to register- based. Several JIT optimizations were turned off. These reverted changes made JIT slower but more stable. Reference PR: https://github.com/ruby/ruby/pull/1782 Reference ticket: https://bugs.ruby-lang.org/issues/14235 Partially merged in trunk 10 days ago. Able to run Rails stably.
  • 20. Demo time source at github://vessi/rm20.git
  • 21. Future of JIT in Ruby
  • 22. Well, it will just appear in 2.6 release. You don’t need to wait to 3.0
  • 25. My friends are looking for normal Ruby developer (not another me)