SlideShare a Scribd company logo
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)

More Related Content

PDF
Rubinius - Ruby Implemented with Ruby
PPTX
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
PDF
mRuby - Powerful Software for Embedded System Development
PDF
GraalVM - JBCNConf 2019-05-28
PDF
It's a Jungle Out There – IoT and MRuby
PPTX
Coroutines in Kotlin
PDF
Jython in workflow and rules engines
PDF
Powerlang: a Vehicle for Lively Implementing Programming Languages
Rubinius - Ruby Implemented with Ruby
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
mRuby - Powerful Software for Embedded System Development
GraalVM - JBCNConf 2019-05-28
It's a Jungle Out There – IoT and MRuby
Coroutines in Kotlin
Jython in workflow and rules engines
Powerlang: a Vehicle for Lively Implementing Programming Languages

What's hot (19)

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

Similar to Ruby JIT Compilation - Mykhail Bortnyk (20)

PPTX
#JavaOne What's in an object?
PPTX
JavaOne2015-What's in an Object?
PDF
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
PPTX
Micronaut: A new way to build microservices
DOCX
just in time JIT compiler
PPT
Java2020 programming basics and fundamentals
KEY
Concurrency in ruby
PPT
Introduction to .net
PDF
Oh the compilers you'll build
PDF
WebGL games with Minko - Next Game Frontier 2014
PDF
Tutorial c#
PPT
.Net introduction by Quontra Solutions
PPTX
PDF
Gwt kickoff - Alberto Mancini & Francesca Tosi
PDF
WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...
PDF
Javascript as a target language - GWT KickOff - Part 2/2
PDF
TechEvent Graal(VM) Performance Interoperability
PDF
WebAssembly is Key to Better LLM Performance
PDF
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
PPT
Dynamic Languages on the JVM
#JavaOne What's in an object?
JavaOne2015-What's in an Object?
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
Micronaut: A new way to build microservices
just in time JIT compiler
Java2020 programming basics and fundamentals
Concurrency in ruby
Introduction to .net
Oh the compilers you'll build
WebGL games with Minko - Next Game Frontier 2014
Tutorial c#
.Net introduction by Quontra Solutions
Gwt kickoff - Alberto Mancini & Francesca Tosi
WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...
Javascript as a target language - GWT KickOff - Part 2/2
TechEvent Graal(VM) Performance Interoperability
WebAssembly is Key to Better LLM Performance
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Dynamic Languages on the JVM
Ad

More from Ruby Meditation (20)

PDF
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30
PDF
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
PDF
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
PDF
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
PDF
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
PDF
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
PDF
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
PDF
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
PDF
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
PDF
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
PDF
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
PDF
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
PDF
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
PDF
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
PDF
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
PDF
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
PDF
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
PDF
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
PDF
Rails App performance at the limit - Bogdan Gusiev
PDF
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
Rails App performance at the limit - Bogdan Gusiev
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Machine learning based COVID-19 study performance prediction
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Big Data Technologies - Introduction.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
KodekX | Application Modernization Development
PPTX
Cloud computing and distributed systems.
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation theory and applications.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
cuic standard and advanced reporting.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectral efficient network and resource selection model in 5G networks
Machine learning based COVID-19 study performance prediction
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Big Data Technologies - Introduction.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
KodekX | Application Modernization Development
Cloud computing and distributed systems.
MYSQL Presentation for SQL database connectivity
Mobile App Security Testing_ A Comprehensive Guide.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Chapter 3 Spatial Domain Image Processing.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
A Presentation on Artificial Intelligence
Encapsulation theory and applications.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
cuic standard and advanced reporting.pdf
NewMind AI Monthly Chronicles - July 2025
Advanced methodologies resolving dimensionality complications for autism neur...
Diabetes mellitus diagnosis method based random forest with bat algorithm

Ruby JIT Compilation - Mykhail Bortnyk

  • 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)