SlideShare a Scribd company logo
Accelerating Ruby
                              with LLVM
                                 Evan Phoenix
                                 Oct 2, 2009

Tuesday, October 6, 2009
RUBY


Tuesday, October 6, 2009
RUBY
                           Strongly, dynamically typed




Tuesday, October 6, 2009
RUBY
                           Unified Model




Tuesday, October 6, 2009
RUBY
                           Everything is an object




Tuesday, October 6, 2009
RUBY
                           3.class # => Fixnum




Tuesday, October 6, 2009
RUBY
                           Every code context is equal




Tuesday, October 6, 2009
RUBY
                           Every context is a method




Tuesday, October 6, 2009
RUBY
                           Garbage Collected




Tuesday, October 6, 2009
RUBY
                           A lot of syntax




Tuesday, October 6, 2009
RUBY
                           Strongly, dynamically typed Every code context is equal
                                 Unified model           Every context is a method
                             Everything is an object        Garbage collected
                                      3.class                A lot of syntax



Tuesday, October 6, 2009
Rubinius


Tuesday, October 6, 2009
Rubinius
                           Started in 2006




Tuesday, October 6, 2009
Rubinius
                           Build a ruby environment for fun




Tuesday, October 6, 2009
Rubinius
                           Unlike most “scripting” languages,
                           write as much in ruby as possible



Tuesday, October 6, 2009
Rubinius
                  Core functionality of perl/python/ruby in C,
                      NOT in their respective language.



Tuesday, October 6, 2009
Rubinius
                           C => ruby => C => ruby




Tuesday, October 6, 2009
Rubinius
                           Language boundaries suck




Tuesday, October 6, 2009
Rubinius
                                Started in 2006
                                  Built for fun
                           Turtles all the way down


Tuesday, October 6, 2009
Evolution


Tuesday, October 6, 2009
Evolution
                           100% ruby prototype running on 1.8




Tuesday, October 6, 2009
Evolution
                           Hand translated VM to C




Tuesday, October 6, 2009
Evolution
                           Rewrote VM in C++




Tuesday, October 6, 2009
Evolution
                           Switch away from stackless




Tuesday, October 6, 2009
Evolution
                           Experimented with handwritten
                                 assembler for x86



Tuesday, October 6, 2009
Evolution
                           Switch to LLVM for JIT




Tuesday, October 6, 2009
Evolution
                            100% ruby prototype      Switch away from stackless
                           Hand translated VM to C   Experiment with assembler
                             Rewrote VM in C++         Switch to LLVM for JIT




Tuesday, October 6, 2009
Features


Tuesday, October 6, 2009
Features
                           Bytecode VM




Tuesday, October 6, 2009
Features
                           Simple interface to native code




Tuesday, October 6, 2009
Features
                           Accurate, generational garbage collector




Tuesday, October 6, 2009
Features
                           Integrated FFI API




Tuesday, October 6, 2009
Features
               Bytecode VM        Generational GC
         Interface to native code  Integrated FFI


Tuesday, October 6, 2009
Benchmarks


Tuesday, October 6, 2009
def foo()
                             ary = []
                             100.times { |i| ary << i }
                           end



                                                      300,000 times
Tuesday, October 6, 2009
Seconds
                             9


                                  8.02


                           6.75

                                                5.90
                                         5.30
                            4.5


                                                        3.60


                           2.25                                       2.59




                             0
                                  1.8    1.9    rbx    rbx jit   rbx jit +blocks


Tuesday, October 6, 2009
def foo()
                             hsh = {}
                             100.times { |i| hsh[i] = 0 }
                           end



                                                       100,000 times
Tuesday, October 6, 2009
Seconds
                            30



                                                25.36

                           22.5




                            15

                                                        12.54
                                                                       12.01


                            7.5

                                  4.85   5.26



                             0
                                  1.8    1.9    rbx     rbx jit   rbx jit +blocks


Tuesday, October 6, 2009
def foo()
                             hsh = { 47 => true }
                             100.times { |i| hsh[i] }
                           end



                                                        100,000 times
Tuesday, October 6, 2009
Seconds
                             7


                                                6.26


                           5.25




                            3.5   3.64


                                                        2.68          2.66

                                         2.09
                           1.75




                             0
                                  1.8    1.9    rbx    rbx jit   rbx jit +blocks


Tuesday, October 6, 2009
Early LLVM Usage


Tuesday, October 6, 2009
Early LLVM Usage
                           Compiled all methods up front




Tuesday, October 6, 2009
Early LLVM Usage
                           Simple opcode-to-function translation
                                       with inlining



Tuesday, October 6, 2009
Early LLVM Usage
                           Startup went from 0.3s to 80s




Tuesday, October 6, 2009
Early LLVM Usage
                               Compiled all methods upfront
                            Simple opcode-to-function translation
                                  Startup from 0.3s to 80s




Tuesday, October 6, 2009
True JIT


Tuesday, October 6, 2009
True JIT
                            JIT Goals




Tuesday, October 6, 2009
True JIT
                                       JIT Goals
                           Choose methods that benefit the most




Tuesday, October 6, 2009
True JIT
                                           JIT Goals
                           Compiling has minimum impact on performance




Tuesday, October 6, 2009
True JIT
                                           JIT Goals
                           Ability to make intelligent frontend decisions




Tuesday, October 6, 2009
Choosing Methods


Tuesday, October 6, 2009
Choosing Methods
                              Simple call counters




Tuesday, October 6, 2009
Choosing Methods
                           When counter trips, the fun starts




Tuesday, October 6, 2009
Choosing Methods
                             Room for improvement




Tuesday, October 6, 2009
Choosing Methods
                             Room for improvement
                              Increment counters in loops




Tuesday, October 6, 2009
Choosing Methods
                               Room for improvement
                            Weigh different invocations differently




Tuesday, October 6, 2009
Choosing Methods
                               Simple counters        Room for improvement
                           Trip the counters, do it     Increment in loops
                                                        Weigh invocations



Tuesday, October 6, 2009
Which Method?


Tuesday, October 6, 2009
Which Method?
                           Leaf methods trip quickly




Tuesday, October 6, 2009
Which Methods?
                            Leaf methods trip quickly
                             Consider the whole callstack




Tuesday, October 6, 2009
Which Methods?
                            Leaf methods trip quickly
                             Pick a parent expecting inlining




Tuesday, October 6, 2009
Which Method?
                             Leaf methods trip
                            Consider the callstack
                               Find a parent


Tuesday, October 6, 2009
Minimal Impact


Tuesday, October 6, 2009
Minimal Impact
                            After the counters trip




Tuesday, October 6, 2009
Minimal Impact
                             Queue the method




Tuesday, October 6, 2009
Minimal Impact
                           Background thread drains queue




Tuesday, October 6, 2009
Minimal Impact
                           Frontend, passes, codegen in background




Tuesday, October 6, 2009
Minimal Impact
                             Install JIT’d function




Tuesday, October 6, 2009
Minimal Impact
                             Install JIT’d function
                             Requires GC interaction




Tuesday, October 6, 2009
Minimal Impact
                  Trip the counters Compile in background
                  Queue the method Install function pointer


Tuesday, October 6, 2009
Good Decisions


Tuesday, October 6, 2009
Good Decisions
                    Naive translation yields fixed improvement




Tuesday, October 6, 2009
Good Decisions
                           Performance shifts to method dispatch




Tuesday, October 6, 2009
Good Decisions
                           Improve optimization horizon




Tuesday, October 6, 2009
Good Decisions
                           Inline using type feedback




Tuesday, October 6, 2009
Good Decisions
                            Naive translation sucks     Performance in dispatch
                           Inline using type feedback    Improve optimizations




Tuesday, October 6, 2009
Type Feedback


Tuesday, October 6, 2009
Type Feedback
                           Frontend translates to IR




Tuesday, October 6, 2009
Type Feedback
                           Read InlineCache information




Tuesday, October 6, 2009
Type Feedback
                           InlineCaches contain profiling info




Tuesday, October 6, 2009
Type Feedback
                           Use profiling to drive inlining!




Tuesday, October 6, 2009
Type Feedback
                           Frontend generates IR    InlineCaches have profiling
                            Reads InlineCaches     Use profiling to drive inlining!




Tuesday, October 6, 2009
Inlining


Tuesday, October 6, 2009
Inlining
                           Profiling info shows a dominant class




Tuesday, October 6, 2009
2
                            1%




                           1 class
                            98%



Tuesday, October 6, 2009
Inlining
                           Lookup method in compiler




Tuesday, October 6, 2009
Inlining
                           For native functions, emit direct call




Tuesday, October 6, 2009
Inlining
                           For FFI, inline conversions and call




Tuesday, October 6, 2009
Inlining
                           Find dominant class
                                                 Emit direct calls if possible
                             Lookup method




Tuesday, October 6, 2009
Inlining Ruby


Tuesday, October 6, 2009
Inlining Ruby
                           Policy decides on inlining




Tuesday, October 6, 2009
Inlining Ruby
                           Drive sub-frontend at call site




Tuesday, October 6, 2009
Inlining Ruby
                           All inlining occurs in the frontend




Tuesday, October 6, 2009
Inlining Ruby
                           Generated IR preserves runtime data




Tuesday, October 6, 2009
Inlining Ruby
                           Generated IR preserves runtime data
                                   GC roots, backtraces, etc




Tuesday, October 6, 2009
Inlining Ruby
                           No AST between bytecode and IR




Tuesday, October 6, 2009
Inlining Ruby
                           No AST between bytecode and IR
                           Fast, but limits the ability to generate better IR




Tuesday, October 6, 2009
Inlining Ruby
                             Policy decides     Preserve runtime data
                           Drive sub-frontend   Generates fast, ugly IR




Tuesday, October 6, 2009
LLVM


Tuesday, October 6, 2009
LLVM
                           IR uses operand stack




Tuesday, October 6, 2009
LLVM
                           IR uses operand stack
                           Highlevel data flow not in SSA




Tuesday, October 6, 2009
LLVM
                           IR uses operand stack
                           Passes eliminate redundencies




Tuesday, October 6, 2009
LLVM
                           IR uses operand stack
                           Makes GC stack marking easy




Tuesday, October 6, 2009
LLVM
                            IR uses operand stack
                           nocapture improves propagation




Tuesday, October 6, 2009
LLVM
                           Exceptions via sentinal value




Tuesday, October 6, 2009
LLVM
                            Exceptions via sentinal value
                           Nested handlers use branches for control




Tuesday, October 6, 2009
LLVM
                           Exceptions via sentinal value
                            Inlining exposes redundant checks




Tuesday, October 6, 2009
LLVM
                           Inline guards




Tuesday, October 6, 2009
LLVM
                           Inline guards
                           Simple type guards




Tuesday, October 6, 2009
if(obj->class->class_id ==
                              <integer constant>) {


Tuesday, October 6, 2009
LLVM
                                     Inline guards
                           Custom AA pass for guard elimination




Tuesday, October 6, 2009
LLVM
                                     Inline guards
                           Teach pointsToConstantMemory about...




Tuesday, October 6, 2009
if(obj->class->class_id ==
                              <integer constant>) {


Tuesday, October 6, 2009
if(obj->class->class_id ==
                              <integer constant>) {


Tuesday, October 6, 2009
LLVM
                           Maximizing constant propagation




Tuesday, October 6, 2009
LLVM
                           Maximizing constant propagation
                            Type failures shouldn’t contribute values




Tuesday, October 6, 2009
if(obj->class->class_id == 0x33) {
                             val = 0x7;
                           } else {
                             val = send_msg(state, obj, ...);
                           }



Tuesday, October 6, 2009
if(obj->class->class_id == 0x33) {
                             val = 0x7;
                           } else {
                             return uncommon(state);
                           }



Tuesday, October 6, 2009
LLVM
                           Maximizing constant propagation
                                Makes JIT similar to tracing




Tuesday, October 6, 2009
LLVM
                           Use overflow intrinsics




Tuesday, October 6, 2009
LLVM
                                Use overflow intrinsics
                           Custom pass to fold constants arguments




Tuesday, October 6, 2009
LLVM
                           AA knowledge for tagged pointers




Tuesday, October 6, 2009
LLVM
                           AA knowledge of tagged pointers
                                0x5 is 2 as a tagged pointer




Tuesday, October 6, 2009
LLVM
                             Not in SSA form       Maximize constants
                           Simplistic exceptions     Use overflow
                              Inlining guards      Tagged pointer AA




Tuesday, October 6, 2009
Issues


Tuesday, October 6, 2009
Issues
                           How to link with LLVM?




Tuesday, October 6, 2009
Issues
                           How to link with LLVM?
                             An important SCM issue




Tuesday, October 6, 2009
Issues
                           Ugly, confusing IR from frontend




Tuesday, October 6, 2009
Issues
                           instcombine confuses basicaa




Tuesday, October 6, 2009
Issues
                           Operand stack confuses AA




Tuesday, October 6, 2009
Issues
                           Inability to communicate semantics




Tuesday, October 6, 2009
Object* new_object(state)




Tuesday, October 6, 2009
Returned pointer aliases nothing

                                 Only modifies state

                                          If return value is unused, remove the call




                                                Semi-pure?

Tuesday, October 6, 2009
Issues
                                 Ugly IR          AA confusion
                           Linking with LLVM   Highlevel semantics




Tuesday, October 6, 2009
Thanks!

                                http://rubini.us
                           ephoenix@engineyard.com


Tuesday, October 6, 2009
Ad

More Related Content

Similar to Accelerating Ruby with LLVM (12)

Vladimir Oane
Vladimir OaneVladimir Oane
Vladimir Oane
evensys
 
Vagrant at LA Ruby
Vagrant at LA RubyVagrant at LA Ruby
Vagrant at LA Ruby
Mitchell Hashimoto
 
Mkt571.Augsep09.1.Slideshare
Mkt571.Augsep09.1.SlideshareMkt571.Augsep09.1.Slideshare
Mkt571.Augsep09.1.Slideshare
Lawrence
 
MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meet
Matt Aimonetti
 
BDW: How To Pitch Your Ideas
BDW: How To Pitch Your IdeasBDW: How To Pitch Your Ideas
BDW: How To Pitch Your Ideas
David Cohen
 
Plone on Amazon EC2
Plone on Amazon EC2Plone on Amazon EC2
Plone on Amazon EC2
Jazkarta, Inc.
 
Talk About Configuration Management
Talk About Configuration ManagementTalk About Configuration Management
Talk About Configuration Management
Guixing Bai
 
The Type We Want
The Type We WantThe Type We Want
The Type We Want
Jonathan Snook
 
Edo Cabinet
Edo CabinetEdo Cabinet
Edo Cabinet
John Mettraux
 
Rails3: Stepping off of the golden path
Rails3: Stepping off of the golden pathRails3: Stepping off of the golden path
Rails3: Stepping off of the golden path
Matt Aimonetti
 
Making Design By Committee Work
Making Design By Committee WorkMaking Design By Committee Work
Making Design By Committee Work
Mushon Zer-Aviv
 
ERECOMPI
ERECOMPIERECOMPI
ERECOMPI
Fabio Akita
 
Vladimir Oane
Vladimir OaneVladimir Oane
Vladimir Oane
evensys
 
Mkt571.Augsep09.1.Slideshare
Mkt571.Augsep09.1.SlideshareMkt571.Augsep09.1.Slideshare
Mkt571.Augsep09.1.Slideshare
Lawrence
 
MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meet
Matt Aimonetti
 
BDW: How To Pitch Your Ideas
BDW: How To Pitch Your IdeasBDW: How To Pitch Your Ideas
BDW: How To Pitch Your Ideas
David Cohen
 
Talk About Configuration Management
Talk About Configuration ManagementTalk About Configuration Management
Talk About Configuration Management
Guixing Bai
 
Rails3: Stepping off of the golden path
Rails3: Stepping off of the golden pathRails3: Stepping off of the golden path
Rails3: Stepping off of the golden path
Matt Aimonetti
 
Making Design By Committee Work
Making Design By Committee WorkMaking Design By Committee Work
Making Design By Committee Work
Mushon Zer-Aviv
 

More from evanphx (12)

Rubinius For You - GoRuCo
Rubinius For You - GoRuCoRubinius For You - GoRuCo
Rubinius For You - GoRuCo
evanphx
 
Developing a Language
Developing a LanguageDeveloping a Language
Developing a Language
evanphx
 
Rubinius - What Have You Done For Me Lately?
Rubinius - What Have You Done For Me Lately?Rubinius - What Have You Done For Me Lately?
Rubinius - What Have You Done For Me Lately?
evanphx
 
Rubinius - What Have You Done For Me Lately
Rubinius - What Have You Done For Me LatelyRubinius - What Have You Done For Me Lately
Rubinius - What Have You Done For Me Lately
evanphx
 
Staking Your Claim In Open Source
Staking Your Claim In Open SourceStaking Your Claim In Open Source
Staking Your Claim In Open Source
evanphx
 
Rubinius 1.0 and more!
Rubinius 1.0 and more!Rubinius 1.0 and more!
Rubinius 1.0 and more!
evanphx
 
RubyConf 2009
RubyConf 2009RubyConf 2009
RubyConf 2009
evanphx
 
Ruby World
Ruby WorldRuby World
Ruby World
evanphx
 
Rubinius Community - MWRC
Rubinius Community - MWRCRubinius Community - MWRC
Rubinius Community - MWRC
evanphx
 
rubyconf 2007 - Rubinius 1.0
rubyconf 2007 - Rubinius 1.0rubyconf 2007 - Rubinius 1.0
rubyconf 2007 - Rubinius 1.0
evanphx
 
Rubinius - Improving the Rails ecosystem
Rubinius - Improving the Rails ecosystemRubinius - Improving the Rails ecosystem
Rubinius - Improving the Rails ecosystem
evanphx
 
Rubinius - A Tool of the Future
Rubinius - A Tool of the FutureRubinius - A Tool of the Future
Rubinius - A Tool of the Future
evanphx
 
Rubinius For You - GoRuCo
Rubinius For You - GoRuCoRubinius For You - GoRuCo
Rubinius For You - GoRuCo
evanphx
 
Developing a Language
Developing a LanguageDeveloping a Language
Developing a Language
evanphx
 
Rubinius - What Have You Done For Me Lately?
Rubinius - What Have You Done For Me Lately?Rubinius - What Have You Done For Me Lately?
Rubinius - What Have You Done For Me Lately?
evanphx
 
Rubinius - What Have You Done For Me Lately
Rubinius - What Have You Done For Me LatelyRubinius - What Have You Done For Me Lately
Rubinius - What Have You Done For Me Lately
evanphx
 
Staking Your Claim In Open Source
Staking Your Claim In Open SourceStaking Your Claim In Open Source
Staking Your Claim In Open Source
evanphx
 
Rubinius 1.0 and more!
Rubinius 1.0 and more!Rubinius 1.0 and more!
Rubinius 1.0 and more!
evanphx
 
RubyConf 2009
RubyConf 2009RubyConf 2009
RubyConf 2009
evanphx
 
Ruby World
Ruby WorldRuby World
Ruby World
evanphx
 
Rubinius Community - MWRC
Rubinius Community - MWRCRubinius Community - MWRC
Rubinius Community - MWRC
evanphx
 
rubyconf 2007 - Rubinius 1.0
rubyconf 2007 - Rubinius 1.0rubyconf 2007 - Rubinius 1.0
rubyconf 2007 - Rubinius 1.0
evanphx
 
Rubinius - Improving the Rails ecosystem
Rubinius - Improving the Rails ecosystemRubinius - Improving the Rails ecosystem
Rubinius - Improving the Rails ecosystem
evanphx
 
Rubinius - A Tool of the Future
Rubinius - A Tool of the FutureRubinius - A Tool of the Future
Rubinius - A Tool of the Future
evanphx
 
Ad

Recently uploaded (20)

IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Ad

Accelerating Ruby with LLVM

  • 1. Accelerating Ruby with LLVM Evan Phoenix Oct 2, 2009 Tuesday, October 6, 2009
  • 3. RUBY Strongly, dynamically typed Tuesday, October 6, 2009
  • 4. RUBY Unified Model Tuesday, October 6, 2009
  • 5. RUBY Everything is an object Tuesday, October 6, 2009
  • 6. RUBY 3.class # => Fixnum Tuesday, October 6, 2009
  • 7. RUBY Every code context is equal Tuesday, October 6, 2009
  • 8. RUBY Every context is a method Tuesday, October 6, 2009
  • 9. RUBY Garbage Collected Tuesday, October 6, 2009
  • 10. RUBY A lot of syntax Tuesday, October 6, 2009
  • 11. RUBY Strongly, dynamically typed Every code context is equal Unified model Every context is a method Everything is an object Garbage collected 3.class A lot of syntax Tuesday, October 6, 2009
  • 13. Rubinius Started in 2006 Tuesday, October 6, 2009
  • 14. Rubinius Build a ruby environment for fun Tuesday, October 6, 2009
  • 15. Rubinius Unlike most “scripting” languages, write as much in ruby as possible Tuesday, October 6, 2009
  • 16. Rubinius Core functionality of perl/python/ruby in C, NOT in their respective language. Tuesday, October 6, 2009
  • 17. Rubinius C => ruby => C => ruby Tuesday, October 6, 2009
  • 18. Rubinius Language boundaries suck Tuesday, October 6, 2009
  • 19. Rubinius Started in 2006 Built for fun Turtles all the way down Tuesday, October 6, 2009
  • 21. Evolution 100% ruby prototype running on 1.8 Tuesday, October 6, 2009
  • 22. Evolution Hand translated VM to C Tuesday, October 6, 2009
  • 23. Evolution Rewrote VM in C++ Tuesday, October 6, 2009
  • 24. Evolution Switch away from stackless Tuesday, October 6, 2009
  • 25. Evolution Experimented with handwritten assembler for x86 Tuesday, October 6, 2009
  • 26. Evolution Switch to LLVM for JIT Tuesday, October 6, 2009
  • 27. Evolution 100% ruby prototype Switch away from stackless Hand translated VM to C Experiment with assembler Rewrote VM in C++ Switch to LLVM for JIT Tuesday, October 6, 2009
  • 29. Features Bytecode VM Tuesday, October 6, 2009
  • 30. Features Simple interface to native code Tuesday, October 6, 2009
  • 31. Features Accurate, generational garbage collector Tuesday, October 6, 2009
  • 32. Features Integrated FFI API Tuesday, October 6, 2009
  • 33. Features Bytecode VM Generational GC Interface to native code Integrated FFI Tuesday, October 6, 2009
  • 35. def foo() ary = [] 100.times { |i| ary << i } end 300,000 times Tuesday, October 6, 2009
  • 36. Seconds 9 8.02 6.75 5.90 5.30 4.5 3.60 2.25 2.59 0 1.8 1.9 rbx rbx jit rbx jit +blocks Tuesday, October 6, 2009
  • 37. def foo() hsh = {} 100.times { |i| hsh[i] = 0 } end 100,000 times Tuesday, October 6, 2009
  • 38. Seconds 30 25.36 22.5 15 12.54 12.01 7.5 4.85 5.26 0 1.8 1.9 rbx rbx jit rbx jit +blocks Tuesday, October 6, 2009
  • 39. def foo() hsh = { 47 => true } 100.times { |i| hsh[i] } end 100,000 times Tuesday, October 6, 2009
  • 40. Seconds 7 6.26 5.25 3.5 3.64 2.68 2.66 2.09 1.75 0 1.8 1.9 rbx rbx jit rbx jit +blocks Tuesday, October 6, 2009
  • 41. Early LLVM Usage Tuesday, October 6, 2009
  • 42. Early LLVM Usage Compiled all methods up front Tuesday, October 6, 2009
  • 43. Early LLVM Usage Simple opcode-to-function translation with inlining Tuesday, October 6, 2009
  • 44. Early LLVM Usage Startup went from 0.3s to 80s Tuesday, October 6, 2009
  • 45. Early LLVM Usage Compiled all methods upfront Simple opcode-to-function translation Startup from 0.3s to 80s Tuesday, October 6, 2009
  • 47. True JIT JIT Goals Tuesday, October 6, 2009
  • 48. True JIT JIT Goals Choose methods that benefit the most Tuesday, October 6, 2009
  • 49. True JIT JIT Goals Compiling has minimum impact on performance Tuesday, October 6, 2009
  • 50. True JIT JIT Goals Ability to make intelligent frontend decisions Tuesday, October 6, 2009
  • 52. Choosing Methods Simple call counters Tuesday, October 6, 2009
  • 53. Choosing Methods When counter trips, the fun starts Tuesday, October 6, 2009
  • 54. Choosing Methods Room for improvement Tuesday, October 6, 2009
  • 55. Choosing Methods Room for improvement Increment counters in loops Tuesday, October 6, 2009
  • 56. Choosing Methods Room for improvement Weigh different invocations differently Tuesday, October 6, 2009
  • 57. Choosing Methods Simple counters Room for improvement Trip the counters, do it Increment in loops Weigh invocations Tuesday, October 6, 2009
  • 59. Which Method? Leaf methods trip quickly Tuesday, October 6, 2009
  • 60. Which Methods? Leaf methods trip quickly Consider the whole callstack Tuesday, October 6, 2009
  • 61. Which Methods? Leaf methods trip quickly Pick a parent expecting inlining Tuesday, October 6, 2009
  • 62. Which Method? Leaf methods trip Consider the callstack Find a parent Tuesday, October 6, 2009
  • 64. Minimal Impact After the counters trip Tuesday, October 6, 2009
  • 65. Minimal Impact Queue the method Tuesday, October 6, 2009
  • 66. Minimal Impact Background thread drains queue Tuesday, October 6, 2009
  • 67. Minimal Impact Frontend, passes, codegen in background Tuesday, October 6, 2009
  • 68. Minimal Impact Install JIT’d function Tuesday, October 6, 2009
  • 69. Minimal Impact Install JIT’d function Requires GC interaction Tuesday, October 6, 2009
  • 70. Minimal Impact Trip the counters Compile in background Queue the method Install function pointer Tuesday, October 6, 2009
  • 72. Good Decisions Naive translation yields fixed improvement Tuesday, October 6, 2009
  • 73. Good Decisions Performance shifts to method dispatch Tuesday, October 6, 2009
  • 74. Good Decisions Improve optimization horizon Tuesday, October 6, 2009
  • 75. Good Decisions Inline using type feedback Tuesday, October 6, 2009
  • 76. Good Decisions Naive translation sucks Performance in dispatch Inline using type feedback Improve optimizations Tuesday, October 6, 2009
  • 78. Type Feedback Frontend translates to IR Tuesday, October 6, 2009
  • 79. Type Feedback Read InlineCache information Tuesday, October 6, 2009
  • 80. Type Feedback InlineCaches contain profiling info Tuesday, October 6, 2009
  • 81. Type Feedback Use profiling to drive inlining! Tuesday, October 6, 2009
  • 82. Type Feedback Frontend generates IR InlineCaches have profiling Reads InlineCaches Use profiling to drive inlining! Tuesday, October 6, 2009
  • 84. Inlining Profiling info shows a dominant class Tuesday, October 6, 2009
  • 85. 2 1% 1 class 98% Tuesday, October 6, 2009
  • 86. Inlining Lookup method in compiler Tuesday, October 6, 2009
  • 87. Inlining For native functions, emit direct call Tuesday, October 6, 2009
  • 88. Inlining For FFI, inline conversions and call Tuesday, October 6, 2009
  • 89. Inlining Find dominant class Emit direct calls if possible Lookup method Tuesday, October 6, 2009
  • 91. Inlining Ruby Policy decides on inlining Tuesday, October 6, 2009
  • 92. Inlining Ruby Drive sub-frontend at call site Tuesday, October 6, 2009
  • 93. Inlining Ruby All inlining occurs in the frontend Tuesday, October 6, 2009
  • 94. Inlining Ruby Generated IR preserves runtime data Tuesday, October 6, 2009
  • 95. Inlining Ruby Generated IR preserves runtime data GC roots, backtraces, etc Tuesday, October 6, 2009
  • 96. Inlining Ruby No AST between bytecode and IR Tuesday, October 6, 2009
  • 97. Inlining Ruby No AST between bytecode and IR Fast, but limits the ability to generate better IR Tuesday, October 6, 2009
  • 98. Inlining Ruby Policy decides Preserve runtime data Drive sub-frontend Generates fast, ugly IR Tuesday, October 6, 2009
  • 100. LLVM IR uses operand stack Tuesday, October 6, 2009
  • 101. LLVM IR uses operand stack Highlevel data flow not in SSA Tuesday, October 6, 2009
  • 102. LLVM IR uses operand stack Passes eliminate redundencies Tuesday, October 6, 2009
  • 103. LLVM IR uses operand stack Makes GC stack marking easy Tuesday, October 6, 2009
  • 104. LLVM IR uses operand stack nocapture improves propagation Tuesday, October 6, 2009
  • 105. LLVM Exceptions via sentinal value Tuesday, October 6, 2009
  • 106. LLVM Exceptions via sentinal value Nested handlers use branches for control Tuesday, October 6, 2009
  • 107. LLVM Exceptions via sentinal value Inlining exposes redundant checks Tuesday, October 6, 2009
  • 108. LLVM Inline guards Tuesday, October 6, 2009
  • 109. LLVM Inline guards Simple type guards Tuesday, October 6, 2009
  • 110. if(obj->class->class_id == <integer constant>) { Tuesday, October 6, 2009
  • 111. LLVM Inline guards Custom AA pass for guard elimination Tuesday, October 6, 2009
  • 112. LLVM Inline guards Teach pointsToConstantMemory about... Tuesday, October 6, 2009
  • 113. if(obj->class->class_id == <integer constant>) { Tuesday, October 6, 2009
  • 114. if(obj->class->class_id == <integer constant>) { Tuesday, October 6, 2009
  • 115. LLVM Maximizing constant propagation Tuesday, October 6, 2009
  • 116. LLVM Maximizing constant propagation Type failures shouldn’t contribute values Tuesday, October 6, 2009
  • 117. if(obj->class->class_id == 0x33) { val = 0x7; } else { val = send_msg(state, obj, ...); } Tuesday, October 6, 2009
  • 118. if(obj->class->class_id == 0x33) { val = 0x7; } else { return uncommon(state); } Tuesday, October 6, 2009
  • 119. LLVM Maximizing constant propagation Makes JIT similar to tracing Tuesday, October 6, 2009
  • 120. LLVM Use overflow intrinsics Tuesday, October 6, 2009
  • 121. LLVM Use overflow intrinsics Custom pass to fold constants arguments Tuesday, October 6, 2009
  • 122. LLVM AA knowledge for tagged pointers Tuesday, October 6, 2009
  • 123. LLVM AA knowledge of tagged pointers 0x5 is 2 as a tagged pointer Tuesday, October 6, 2009
  • 124. LLVM Not in SSA form Maximize constants Simplistic exceptions Use overflow Inlining guards Tagged pointer AA Tuesday, October 6, 2009
  • 126. Issues How to link with LLVM? Tuesday, October 6, 2009
  • 127. Issues How to link with LLVM? An important SCM issue Tuesday, October 6, 2009
  • 128. Issues Ugly, confusing IR from frontend Tuesday, October 6, 2009
  • 129. Issues instcombine confuses basicaa Tuesday, October 6, 2009
  • 130. Issues Operand stack confuses AA Tuesday, October 6, 2009
  • 131. Issues Inability to communicate semantics Tuesday, October 6, 2009
  • 133. Returned pointer aliases nothing Only modifies state If return value is unused, remove the call Semi-pure? Tuesday, October 6, 2009
  • 134. Issues Ugly IR AA confusion Linking with LLVM Highlevel semantics Tuesday, October 6, 2009
  • 135. Thanks! http://rubini.us [email protected] Tuesday, October 6, 2009