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

More Related Content

What's hot

Intoduction to Android Development
Intoduction to Android DevelopmentIntoduction to Android Development
Intoduction to Android DevelopmentBen Hardill
 
GraalVM - OpenSlava 2019-10-18
GraalVM - OpenSlava 2019-10-18GraalVM - OpenSlava 2019-10-18
GraalVM - OpenSlava 2019-10-18Jorge Hidalgo
 
Alternative approach to native Kotlin
Alternative approach to native KotlinAlternative approach to native Kotlin
Alternative approach to native KotlinAndrei Chernyshev
 
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 HeroEPAM
 
Venkat Subramaniam Building DSLs In Groovy
Venkat Subramaniam Building DSLs In GroovyVenkat Subramaniam Building DSLs In Groovy
Venkat Subramaniam Building DSLs In Groovydeimos
 
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 LanguagesFAST
 
PHP vs Node.js
PHP vs Node.jsPHP vs Node.js
PHP vs Node.jsSquareboat
 
使用Eclipse快樂的mruby開發
使用Eclipse快樂的mruby開發使用Eclipse快樂的mruby開發
使用Eclipse快樂的mruby開發yamanekko
 
MacRuby For Ruby Developers
MacRuby For Ruby DevelopersMacRuby For Ruby Developers
MacRuby For Ruby DevelopersRenzo Borgatti
 
Custom angular libraries
Custom angular librariesCustom angular libraries
Custom angular librariesMattVaughn9
 
Stockholm JAM September 2018
Stockholm JAM September 2018Stockholm JAM September 2018
Stockholm JAM September 2018Andrey Devyatkin
 
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 Languagesdeimos
 
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 JVMCharles Anderson
 
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 golangDaniel Czerwonk
 
Free the Functions with Fn project!
Free the Functions with Fn project!Free the Functions with Fn project!
Free the Functions with Fn project!J On The Beach
 
Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finessemzgubin
 
React web development
React web developmentReact web development
React web developmentRully Ramanda
 

What's hot (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
 

Similar to Ruby JIT Compilation

JavaOne2015-What's in an Object?
JavaOne2015-What's in an Object?JavaOne2015-What's in an Object?
JavaOne2015-What's in an Object?Charlie Gracie
 
#JavaOne What's in an object?
#JavaOne What's in an object?#JavaOne What's in an object?
#JavaOne What's in an object?Charlie Gracie
 
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 CompilationMatthew Gaudet
 
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 microservicesLuram Archanjo
 
just in time JIT compiler
just in time JIT compilerjust in time JIT compiler
just in time JIT compilerMohit kumar
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll buildMark Stoodley
 
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 2014Minko3D
 
.Net introduction by Quontra Solutions
.Net introduction by Quontra Solutions.Net introduction by Quontra Solutions
.Net introduction by Quontra SolutionsQUONTRASOLUTIONS
 
Gwt kickoff - Alberto Mancini & Francesca Tosi
Gwt kickoff - Alberto Mancini & Francesca TosiGwt kickoff - Alberto Mancini & Francesca Tosi
Gwt kickoff - Alberto Mancini & Francesca Tosifirenze-gtug
 
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...Igalia
 
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/2JooinK
 
TechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance InteroperabilityTechEvent Graal(VM) Performance Interoperability
TechEvent Graal(VM) Performance InteroperabilityTrivadis
 
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 JVMelliando dias
 
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 ApproachesLinaro
 

Similar to 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
 

More from Amoniac OÜ

Dokku your own heroku 21
Dokku   your own heroku 21Dokku   your own heroku 21
Dokku your own heroku 21Amoniac OÜ
 
GO in Heterogeneous Language Environments
GO in Heterogeneous Language EnvironmentsGO in Heterogeneous Language Environments
GO in Heterogeneous Language EnvironmentsAmoniac OÜ
 
Cleaners of Caribbean
Cleaners of CaribbeanCleaners of Caribbean
Cleaners of CaribbeanAmoniac OÜ
 
Ambiguous Sinatra
Ambiguous SinatraAmbiguous Sinatra
Ambiguous SinatraAmoniac OÜ
 
Capistrano and SystemD
Capistrano and SystemDCapistrano and SystemD
Capistrano and SystemDAmoniac OÜ
 
Distributed Cluster in Ruby
Distributed Cluster in RubyDistributed Cluster in Ruby
Distributed Cluster in RubyAmoniac OÜ
 
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 DevelopmentAmoniac OÜ
 
Rubymotion: Overview and Ecosystem
Rubymotion: Overview and EcosystemRubymotion: Overview and Ecosystem
Rubymotion: Overview and EcosystemAmoniac OÜ
 
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 ConsAmoniac OÜ
 
Functional Web Apps with WebMachine Framework
Functional Web Apps with WebMachine FrameworkFunctional Web Apps with WebMachine Framework
Functional Web Apps with WebMachine FrameworkAmoniac OÜ
 
How to Become a Сhef
How to Become a СhefHow to Become a Сhef
How to Become a СhefAmoniac OÜ
 
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 RAMAmoniac OÜ
 
Deployment tales
Deployment talesDeployment tales
Deployment talesAmoniac OÜ
 

More from 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
 

Recently uploaded

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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 WorkerThousandEyes
 
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 Scriptwesley chun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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.pdfhans926745
 
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 RobisonAnna Loughnan Colquhoun
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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 2024Rafal Los
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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?Antenna Manufacturer Coco
 
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 WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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.pdfUK Journal
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
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 2024The Digital Insurer
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 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
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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?
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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
 

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)