Accelerating Ruby with LLVM

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    2 Favorites

    Accelerating Ruby with LLVM - Presentation Transcript

    1. Accelerating Ruby with LLVM Evan Phoenix Oct 2, 2009 Tuesday, October 6, 2009
    2. RUBY 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
    12. Rubinius 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
    20. Evolution 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
    28. Features 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
    34. Benchmarks 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
    46. True JIT 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
    51. Choosing Methods 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
    58. Which Method? 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
    63. Minimal Impact 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
    71. Good Decisions 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
    77. Type Feedback 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
    83. 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
    90. Inlining Ruby 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
    99. LLVM 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
    125. Issues 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
    132. Object* new_object(state) 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

    + evanphxevanphx, 1 month ago

    custom

    666 views, 2 favs, 0 embeds more stats

    Presented at the LLVM developers meeting 2009, show more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 666
      • 666 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 25
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories