Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby under a Microscope

Ruby under a Microscope

Alexandre Quiterio

November 08, 2014
Tweet

More Decks by Alexandre Quiterio

Other Decks in Programming

Transcript

  1. ๏ 1. Motivation ๏ 2. The journey before the runtime

    ๏ 3. YARV ( The Ruby VM ) ๏ 4. Objects, Classes ๏ 5. Ruby GC ๏ 6, 7. Other Ruby Implementations ( JRuby and Rbx ) ๏ 8..Float::INFINITY ( The Future of Ruby ) Outline
  2. – Mindstorms: Children, Computers, Seymour Papert “A programming language is

    like a natural, human language in that it favours certain metaphors, images, and ways of thinking”
  3. ๏ ShermansTravel - TS Memory Leak ๏ ASW - Concept

    Mismatch between ancestors, includes and extends ๏ FollowAnalytics - C Extensions Real World Examples
  4. YARV ๏ Young! ( but it’s changing quickly ) ๏

    For internal use! ๏ Stack Based VM ๏ Direct Threading Interpretation
  5. YARV’s Basic Registers ๏ Program Counter ๏ Stack Pointer ๏

    Current Frame Pointer ๏ Environment Pointer
  6. ๏ Local Access ๏ Dynamic Access ๏ Special Variables ($&,

    $*, $!, $$) ๏ Catch Tables ๏ Ruby Method Types
  7. VM Purpose ๏ Peephole Optimisations • Reduce Instructions Number ๏

    Macro Instructions • Operand Unification • Instruction Unification ๏ Stack Caching • n-level stack caching • Branch Prediction
  8. Summary ๏ Method Dispatch uses the same algorithm with no

    exceptions! ( Class, Module, Object ) ๏ Every Ruby Object is a combination of a class pointer and an array of instance variables ๏ A Ruby Class is a Ruby Object that contains method definitions, attribute names, a superclass pointer and a constants Table. ๏ A Ruby Module is a Ruby Object that also contains method definitions, a superclass pointer, and a constants Table.
  9. Ruby > 2.0.x ! Generational GC: ! Generational hypothesis: Most

    Objects die young! Nursery ( Younger ) College ( Older )
  10. ๏ Ruby splits objects into 2 groups: • Sunny Objects

    ( truthful ) • Shady Objects ( untruthful )
  11. ๏ Ruby for the JVM and JVM for the Ruby

    ๏ Started in 2001 ๏ Usually the fastest Ruby Implementation ๏ Sponsors: Sun, Engine Yard and Red Hat
  12. Mixed-Mode ๏ JRuby has both interpreter and JIT ๏ Cost

    of generating JVM byte code is high ๏ Interpreter runs faster than JVM’s ๏ JRuby before 9000 translates AST nodes to bytecode. ๏ JRuby 9000 has a new IR ๏ New IR is more suited for implementation of traditional compiler optimisations
  13. Rubinius consists of two major components: Kernel VM Byte Code

    Execution Garbage Collection JIT … String Definition Hash Definition Array Definition … C++ Ruby
  14. ๏ Ruby Design Process ๏ Ruby Spec ( consistency between

    impls ) ๏ Concurrency! When and how? ๏ Fragmentation Risk? ๏ Internal Tools, Debugging API and IDE Support? ๏ Let’s kill the GIL? Is that even possible? The future of Ruby as a Lang.