highly surmountable challenges in ruby+omr jit compilation
TRANSCRIPT
![Page 1: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/1.jpg)
Matthew Gaudet, February 4th, 2017
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
![Page 2: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/2.jpg)
What’s Ruby+OMR again?
![Page 3: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/3.jpg)
An Open Source Toolkit for Language
Runtime Technologies.
![Page 4: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/4.jpg)
Garbage
Collector
JIT Compiler
Monitoring
Porting Library
…More!
![Page 5: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/5.jpg)
Goal: Compatibility!
Integrate vs. Replace
![Page 6: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/6.jpg)
+
![Page 7: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/7.jpg)
![Page 8: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/8.jpg)
8
![Page 9: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/9.jpg)
Status Update: 13 Months later
![Page 10: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/10.jpg)
10
![Page 11: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/11.jpg)
11
No JIT….
![Page 12: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/12.jpg)
![Page 13: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/13.jpg)
13
![Page 14: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/14.jpg)
14
![Page 15: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/15.jpg)
Today:
Branch ruby_2_4_omr is current default.
– Based of ruby_2_4 tag
JIT Compiler Hooked up and running Travis tests for OS/X and Linux
– Known issues in make test-all
– Passing make test with count=0
Populated and tagged Issue Tracker
Performance: Less specialization to micro benchmarks, means lower
seeming performance.
– Better software engineering
https://github.com/rubyomr-preview/ruby/issues/
![Page 16: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/16.jpg)
JIT integration
Functional Correctness has been primary objective
– Aiming for pass of test suite at all optimization levels.
–No restrictions on native code used by extension modules
Have added some optimizations, but haven’t done much in the way of
tuning.
Simple compilation control
![Page 17: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/17.jpg)
![Page 18: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/18.jpg)
Our Goal:
YES
Be Part of Delivering 3x3
![Page 19: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/19.jpg)
Why?
We think Ruby could really benefit from having a JIT
compiler.
Lots of pre-built JIT compiler technology in OMR, with
potential for exploitation in Ruby.
What’s in it for us? Validation of the OMR approach
–Community improvement: Having multiple consumers
helps us make it better for everyone!
![Page 20: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/20.jpg)
https://twitter.com/ChrisGSeaton/status/811303853488488448
![Page 21: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/21.jpg)
Competition and Collaboration
Having multiple JITs for CRuby could be a really good thing!
Share the load of creating interface and infrastructure that all
JITs for CRuby can rely on.
Competition helps push things forward
Collaboration helps solve hard problems!
21
![Page 22: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/22.jpg)
22 https://twitter.com/ChrisGSeaton/status/811332662350794752
![Page 23: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/23.jpg)
23
Effort!
Re
su
lts!
![Page 24: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/24.jpg)
![Page 25: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/25.jpg)
Community Challenges!
![Page 26: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/26.jpg)
https://twitter.com/tenderlove/status/765288
21993188147226
![Page 27: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/27.jpg)
Make Tradeoffs that are Right for the Ruby Community
JIT Compilation:
Trade startup speed for peak speed.
Trade footprint for speed.
![Page 28: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/28.jpg)
What do we prioritize?
Time to First Request?
Time to Peak
Performance?
Peak Performance?
100
64 69
3625 30 25 26 25 26 25
1 2 3 4 5 6 7 8 9 10 11
Time per Iteration (s)
Prioritization will be driven by benchmarks from the community.
![Page 29: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/29.jpg)
1. Some CPU intensive applications: OptCarrot2. Some memory intensive application: 3. A startup benchmark: time ruby -e “def f; ‘100’; end; puts f”?
4. Some web application framework benchmark(s)?
http://rubykaigi.org/2016/presentations/MattStudies.html
Benchmarks to aim for?
http://engineering.appfolio.com/appfolio-engineering/2016/12/8/benchmarking-rails
![Page 30: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/30.jpg)
Information Challenges
![Page 31: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/31.jpg)
MRI
Garbage Collector
Ruby IL Generator Optimizer
Code Generator
Runtime Code Cache
YARV Interpreter
![Page 32: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/32.jpg)
JIT VM Symbiosis
VMJIT
Performance
Information
JIT ↔ VM Interface
![Page 33: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/33.jpg)
Infrequent Event Notification
Operations such as
Basic Operation Redefinition
Constant Modification
Class Hierarchy changes.
Unlocks:
–More aggressive specialization, class hierarchy
optimization. Don’t create code for things that haven’t
happened yet!
![Page 34: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/34.jpg)
Stack Peeking Notification
A hook that fires when some piece of code wants to look at a
stack frame – Give the JIT compiler a chance to materialize
what it should have looked like.
Unlocks
–On Stack Replacement: Don’t Execute Code for Things
that might happen!
![Page 35: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/35.jpg)
Basic Block Frequencies
How many times has this basic block been executed?
Unlocks:
Better Optimization: Don’t spend time compiling
on things that won’t get executed!
?
![Page 36: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/36.jpg)
Type Profiling
What types have we seen for this value?
Unlocks:
Speculation and Specialization: Generate code for
the cases we think will happen!
![Page 37: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/37.jpg)
Horizon Challenges
![Page 38: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/38.jpg)
![Page 39: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/39.jpg)
Much of MRI’s core functionality is written in C!
A problem for the optimization horizon!
![Page 40: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/40.jpg)
Optimization Horizon Solutions?
Rewrite all of core in Ruby.
‘Lift the Core’
40
![Page 41: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/41.jpg)
Optimization Horizon Solutions?
Incremental Ruby-fication:
More promising… and easy to get started on in Ruby!
Convert prelude.rb to a ‘prelude’ directory, where Ruby implementations
live.
– Startup concerns (parse overheads) – can be mitigated with YARV
bytecode serialization.
– Longer term: JIT AOT Compilation maybe!
41
![Page 42: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/42.jpg)
Optimization Challenges
![Page 43: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/43.jpg)
An admission:
![Page 44: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/44.jpg)
Testing Challenges
![Page 45: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/45.jpg)
JIT Testing is Hard!
Normal Tests
Finish quickly
Coverage with minimal repetition.
Local reasoning / isolation
No special command lines
Compiler Stress Tests
Need to run code multiple times! – Allow the JIT to kick in, profile data
to be collected, and consumed
Potentially require global
reasoning.
Run in multiple VM instances
under different options.
Writing test cases that can effectively stress the JIT compiler is an art
![Page 46: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/46.jpg)
JIT Testing is Hard!
Other problems:
Isolating test cases from each
other
Time accuracy trade off
Coverage
All these problems of JIT
testing will also be equally
true when running a
gem’s test suite with a
JIT...
![Page 47: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/47.jpg)
My Personal Ruby Hero
Patched ruby/spec to
allow it to work with
repetition
Great win for JIT testing!
![Page 48: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/48.jpg)
Engineering Challenges
![Page 49: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/49.jpg)
Keeping up with the firehose?
How do we keep up to date with the Ruby core?
Some is good software engineering… callback generation was
done precisely to address this concern. But more still needed!
![Page 50: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/50.jpg)
The JIT Needs some cleanup
Callback Generator Ruby code isn’t very good!
–https://github.com/rubyomr-preview/ruby/issues/74
Great task for someone good at writing Ruby!
The makefiles need love
– https://github.com/rubyomr-preview/ruby/issues/8
![Page 51: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/51.jpg)
OMR Challenges
![Page 52: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/52.jpg)
OMR is evolving!
We’ve only been open source for 4.5 months!
Still working on improving our interfaces, our
integration story.
Need to build out a community! This is where you
can help!
![Page 53: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/53.jpg)
Mentorship
I’m committed to helping anyone who
wants to contribute to Ruby+OMR
get up and running.
I’ll write documentation for things that are
unclear
I’ll answer email!I’ll help guide
implementationI’ll be on slack!
I’ll schedule a video chat with you!
![Page 54: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/54.jpg)
Ruby+OMR needs community
interest to survive!
![Page 55: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/55.jpg)
My To-Do List!
1. Make My Mentorship Commitment Clear!
2. I need to start collecting feedback from ruby-coreon what we would need to do to get community
members interested.
3. I need to start demonstrating the kinds of VM
changes a JIT will need.
![Page 56: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/56.jpg)
The Audience To-Do List!
1. Give Ruby+OMR a try
2. Open Issues!
3. Ask about helping! Little things are equally
appreciated!
![Page 57: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/57.jpg)
My thoughts on hitting 3x3:
57
The Work Ahead!
JIT Work VM Work
The VM Work I hope can be shared among competition!
![Page 58: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/58.jpg)
Thank you so much!
![Page 59: Highly Surmountable Challenges in Ruby+OMR JIT Compilation](https://reader030.vdocuments.net/reader030/viewer/2022021507/58cf01d91a28abab738b68a5/html5/thumbnails/59.jpg)
Acknowledgements
https://en.wikipedia.org/wiki/Foundation_%28engineering%29#/media/File:Concrete_cellar_
10007.JPG
http://emojipedia.org/mozilla/firefox-os-2.5/confused-face/