SlideShare ist ein Scribd-Unternehmen logo
1 von 135
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Ähnlich wie Accelerating Ruby with LLVM

Vladimir Oane
Vladimir OaneVladimir Oane
Vladimir Oaneevensys
 
Mkt571.Augsep09.1.Slideshare
Mkt571.Augsep09.1.SlideshareMkt571.Augsep09.1.Slideshare
Mkt571.Augsep09.1.SlideshareLawrence
 
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 meetMatt Aimonetti
 
BDW: How To Pitch Your Ideas
BDW: How To Pitch Your IdeasBDW: How To Pitch Your Ideas
BDW: How To Pitch Your IdeasDavid Cohen
 
Talk About Configuration Management
Talk About Configuration ManagementTalk About Configuration Management
Talk About Configuration ManagementGuixing 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 pathMatt Aimonetti
 
Making Design By Committee Work
Making Design By Committee WorkMaking Design By Committee Work
Making Design By Committee WorkMushon Zer-Aviv
 

Ähnlich wie Accelerating Ruby with LLVM (12)

Vladimir Oane
Vladimir OaneVladimir Oane
Vladimir Oane
 
Vagrant at LA Ruby
Vagrant at LA RubyVagrant at LA Ruby
Vagrant at LA Ruby
 
Mkt571.Augsep09.1.Slideshare
Mkt571.Augsep09.1.SlideshareMkt571.Augsep09.1.Slideshare
Mkt571.Augsep09.1.Slideshare
 
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
 
BDW: How To Pitch Your Ideas
BDW: How To Pitch Your IdeasBDW: How To Pitch Your Ideas
BDW: How To Pitch Your Ideas
 
Plone on Amazon EC2
Plone on Amazon EC2Plone on Amazon EC2
Plone on Amazon EC2
 
Talk About Configuration Management
Talk About Configuration ManagementTalk About Configuration Management
Talk About Configuration Management
 
The Type We Want
The Type We WantThe Type We Want
The Type We Want
 
Edo Cabinet
Edo CabinetEdo Cabinet
Edo Cabinet
 
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
 
Making Design By Committee Work
Making Design By Committee WorkMaking Design By Committee Work
Making Design By Committee Work
 
ERECOMPI
ERECOMPIERECOMPI
ERECOMPI
 

Mehr von evanphx

Rubinius For You - GoRuCo
Rubinius For You - GoRuCoRubinius For You - GoRuCo
Rubinius For You - GoRuCoevanphx
 
Developing a Language
Developing a LanguageDeveloping a Language
Developing a Languageevanphx
 
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 Latelyevanphx
 
Staking Your Claim In Open Source
Staking Your Claim In Open SourceStaking Your Claim In Open Source
Staking Your Claim In Open Sourceevanphx
 
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 2009evanphx
 
Ruby World
Ruby WorldRuby World
Ruby Worldevanphx
 
Rubinius Community - MWRC
Rubinius Community - MWRCRubinius Community - MWRC
Rubinius Community - MWRCevanphx
 
rubyconf 2007 - Rubinius 1.0
rubyconf 2007 - Rubinius 1.0rubyconf 2007 - Rubinius 1.0
rubyconf 2007 - Rubinius 1.0evanphx
 
Rubinius - Improving the Rails ecosystem
Rubinius - Improving the Rails ecosystemRubinius - Improving the Rails ecosystem
Rubinius - Improving the Rails ecosystemevanphx
 
Rubinius - A Tool of the Future
Rubinius - A Tool of the FutureRubinius - A Tool of the Future
Rubinius - A Tool of the Futureevanphx
 

Mehr von evanphx (12)

Rubinius For You - GoRuCo
Rubinius For You - GoRuCoRubinius For You - GoRuCo
Rubinius For You - GoRuCo
 
Developing a Language
Developing a LanguageDeveloping a Language
Developing a Language
 
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?
 
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
 
Staking Your Claim In Open Source
Staking Your Claim In Open SourceStaking Your Claim In Open Source
Staking Your Claim In Open Source
 
Rubinius 1.0 and more!
Rubinius 1.0 and more!Rubinius 1.0 and more!
Rubinius 1.0 and more!
 
RubyConf 2009
RubyConf 2009RubyConf 2009
RubyConf 2009
 
Ruby World
Ruby WorldRuby World
Ruby World
 
Rubinius Community - MWRC
Rubinius Community - MWRCRubinius Community - MWRC
Rubinius Community - MWRC
 
rubyconf 2007 - Rubinius 1.0
rubyconf 2007 - Rubinius 1.0rubyconf 2007 - Rubinius 1.0
rubyconf 2007 - Rubinius 1.0
 
Rubinius - Improving the Rails ecosystem
Rubinius - Improving the Rails ecosystemRubinius - Improving the Rails ecosystem
Rubinius - Improving the Rails ecosystem
 
Rubinius - A Tool of the Future
Rubinius - A Tool of the FutureRubinius - A Tool of the Future
Rubinius - A Tool of the Future
 

Kürzlich hochgeladen

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Kürzlich hochgeladen (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

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 ephoenix@engineyard.com Tuesday, October 6, 2009