Share
Embed
Transcript
86 slides
-
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Op?mizing Ruby with TruffleRuby The Ruby Logo is Copyright (c) 2006, Yukihiro Matsumoto. It is licensed under the terms of the Crea?ve Commons APribu?on-‐ShareAlike 2.5 agreement. Slides from Chris Seaton Oracle Labs @ChrisGSeaton Benoit Daloze @eregontp 15 March 2017 Linz Ruby User Group -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Safe Harbor Statement The following is intended to provide some insight into a line of research in Oracle Labs. It is intended for informa?on purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or func?onality, and should not be relied upon in making purchasing decisions. Oracle reserves the right to alter its development plans and prac?ces at any ?me, and the development, release, and ?ming of any features or func?onality described in connec?on with any Oracle product or service remains at the sole discre?on of Oracle. Any views expressed in this presenta?on are my own and do not necessarily reflect the views of Oracle. 2 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Who am I ? • Benoit Daloze • PhD student at Johannes Kepler University • Research with TruffleRuby on concurrency • MRI and JRuby commiPer • Maintainer of the Ruby Spec Suite (ruby/spec) 3 TwiPer: @eregontp GitHub: @eregon -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Agenda • Introduc?on • Truffle and Ruby implementa?ons • Why is Ruby apparently so hard to run fast? • Par?al Evalua?on • Performance & Compa?bility 4 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Computer Language Benchmarks Game -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Goal: Computer Language Benchmarks Game -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| What is Truffle? -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| How do Ruby interpreters work? -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| x + y * z + x * y z -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| x + y * z + x * y z load_local x load_local y load_local z call :* call :+ -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Just-‐In-‐Time Compilers -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| x + y * z + x * y z load_local x load_local y load_local z call :* call :+ -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| x + y * z + x * y z load_local x load_local y load_local z call :* call :+ pushq %rbp movq %rsp, %rbp movq %rdi, -‐8(%rbp) movq %rsi, -‐16(%rbp) movq %rdx, -‐24(%rbp) movq -‐16(%rbp), %rax movl %eax, %edx movq -‐24(%rbp), %rax imull %edx, %eax movq -‐8(%rbp), %rdx addl %edx, %eax popq %rbp ret -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| The JRuby logo is copyright (c) Tony Price 2011, licensed under the terms of Crea?ve Commons APribu?on-‐NoDerivs 3.0 Unported (CC BY-‐ND 3.0) JRuby JITs by emihng JVM bytecode VM in Java Core library mostly in Java -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| The Rubinius logo is copyright 2011 Shane Becker, licensed under the terms of Crea?ve Commons APribu?on-‐NoDeriva?ves 4.0 Interna?onal — CC BY-‐ND 4.0 Rubinius JITs by emihng LLVM bitcode VM in C++ Core library mostly in Ruby -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| The Rubinius logo is copyright 2011 Shane Becker, licensed under the terms of Crea?ve Commons APribu?on-‐NoDeriva?ves 4.0 Interna?onal — CC BY-‐ND 4.0 Rubinius JITs by emihng LLVM bitcode VM in C++ Core library mostly in Ruby -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| JVM Graal Truffle 23 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Truffle Graal VM JVM 24 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| U U U U U I I I G G I I I G G Node Rewriting for Profiling Feedback AST Interpreter Rewritten Nodes AST Interpreter Uninitialized Nodes Compilation using Partial Evaluation Compiled Code Node Transitions S U I D G Uninitialized Integer Generic Double String T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. Wolczko. One VM to rule them all. In Proceedings of Onward!, 2013. Compiling the AST to machine code -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| T. Würthinger, C. Wimmer, A. Wöß, L. Stadler, G. Duboscq, C. Humer, G. Richards, D. Simon, and M. Wolczko. One VM to rule them all. In Proceedings of Onward!, 2013. I I I G G I I I G G Deoptimization to AST Interpreter D I D G G D I D G G Node Rewriting to Update Profiling Feedback Recompilation using Partial Evaluation Deop?miza?on and recompila?on -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Why is Ruby apparently so hard to run fast? -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| require 'benchmark/ips' Benchmark.ips do |x| x.report( "direct", "14 + 2" ) x.report( "send-‐symbol", "14.send(:+, 2)" ) x.report( "send-‐string", "14.send('+', 2)" ) x.report( "eval", "eval('14 + 2')" ) x.compare! end -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| direct: 37299872.6 i/s send-‐symbol: 13060179.1 i/s -‐ 2.86x slower send-‐string: 4974575.3 i/s -‐ 7.50x slower eval: 171835.9 i/s -‐ 217.07x slower -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Throwing away metaprogramming • Crystal – throws away metaprogramming en?rely to make a faster Ruby • Rubinius – doesn’t support set_trace_func • JRuby – doesn’t support set_trace_func or ObjectSpace • RubyMo?on – doesn’t support eval, Binding -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| How does Truffle + Graal solve this? -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| ParCal EvaluaCon And DeopCmizaCon -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| 42 def min(a, b) [a, b].sort[0] end puts min(2, 8) -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| 43 def min(a, b) [a, b].sort[0] end puts [2, 8].sort[0] -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| 44 t0 = 2 <=> 8 t1 = t0 < 0 ? 2 : 8 t2 = t0 > 0 ? 8 : 2 t3 = [t1, t2] puts t3[0] -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| 45 t0 = 2 <=> 8 t1 = t0 < 0 ? 2 : 8 t2 = t0 > 0 ? 8 : 2 t3 = [t1, t2] puts t1 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| 46 t0 = -1 t1 = t0 < 0 ? 2 : 8 puts t1 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| 47 t0 = -1 t1 = -1 < 0 ? 2 : 8 puts t1 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| 48 t1 = true ? 2 : 8 puts t1 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| 49 t1 = 2 puts t1 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| 50 t1 = 2 puts 2 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| require 'benchmark/ips' Benchmark.ips do |x| x.report( "direct", "14 + 2" ) x.report( "send-‐symbol", "14.send(:+, 2)" ) x.report( "send-‐string", "14.send('+', 2)" ) x.report( "eval", "eval('14 + 2')" ) x.compare! end -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| direct: 37299872.6 i/s send-‐symbol: 13060179.1 i/s -‐ 2.86x slower send-‐string: 4974575.3 i/s -‐ 7.50x slower eval: 171835.9 i/s -‐ 217.07x slower -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| direct: 73099792.5 i/s send-‐symbol: 73458837.7 i/s – difference within err send-‐string: 66882023.8 i/s -‐ difference within err eval: 67024838.3 i/s -‐ difference within err -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| An extreme example -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Speedup rela?ve to MRI -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| • • • • MRI 2.3 JRuby 9.0.4 Node.js JRuby+Truffle Java 1.8.0u66 1 5 10 25 50 75 12 Benchmarks using Objects, Closures and Arrays from hPps://github.com/smarr/are-‐we-‐fast-‐yet TruffleRuby -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| 71 Optcarrot: NES emulator benchmark -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Optcarrot: NES emulator benchmark – 9x faster than MRI 72 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| 73 Demo Time ! -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Language specs 96% Core library specs 100% 92% C-‐extension API specs Ruby specs 75 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| But does it run “Rails”, “Ruby on Rails”, and the Rails logo are registered trademarks of David Heinemeier Hansson ? -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Rails tests Ac?ve Model Ac?ve Support Ac?ve Record Ac?on View Ac?on Pack Ac?on Mailer Rail?es Sprockets-‐Rails Ac?ve Job Spring 100% 100% 98% Basic func0onality works 37% 78 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| So then why can’t we run real applica?ons yet? • C extensions are s?ll a work in progress – Almost no database drivers – No openssl – No nokogiri – Prevents us running almost everything unfortunately • The specs don’t have perfect coverage 79 -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Ongoing Research • Running C extension with Sulong (Truffle+LLVM) • ObjectSpace: stop the world and walk the frames • Represen?ng String as Ropes • Efficient parallelism: • Thread-‐Safe Objects for Dynamic Languages • Thread-‐Safe and Scalable Ruby collec?ons -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Conclusions Simple VM ideas can solve the major problems of making Ruby fast -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Conclusions Simple VM ideas can solve the major problems of making Ruby fast We don’t need to tell Ruby programmers to avoid language features to get performance -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| Where to get more info -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| hPps://github.com/graalvm/truffleruby (or just search for “truffleruby”) -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| 85 Search for ’graal otn’ www.oracle.com/technetwork/oracle-‐labs/program-‐languages -
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
| 86 Acknowledgements Oracle Danilo Ansaloni Stefan Anzinger Cosmin Basca Daniele BonePa MaPhias Brantner Petr Chalupa Jürgen Christ Laurent Daynès Gilles Duboscq Mar?n Entlicher Brandon Fish Bas?an Hossbach Chris?an Humer Mick Jordan Vojin Jovanovic Peter Kessler David Leopoldseder Duncan MacGregor Kevin Menard Jakub Podlešák Aleksandar Prokopec Tom Rodriguez Oracle (con0nued) Roland Schatz Chris Seaton Doug Simon Štěpán Šindelář Zbyněk Šlajchrt Lukas Stadler Codrut Stancu Jan Štola Jaroslav Tulach Michael Van De Vanter Adam Welc Chris?an Wimmer Chris?an Wirth Paul Wögerer Mario Wolczko Andreas Wöß Thomas Würthinger JKU Linz Prof. Hanspeter Mössenböck Benoit Daloze Josef Eisl Thomas Feich?nger MaPhias Grimmer Chris?an Häubl Josef Haider Chris?an Huber Stefan Marr Manuel Rigger Stefan Rumzucker Bernhard Urban University of Edinburgh Christophe Dubach Juan José Fumero Alfonso Ranjeet Singh Toomas Remmelg LaBRI Floréal Morandat University of California, Irvine Prof. Michael Franz Gulfem Savrun Yeniceri Wei Zhang Purdue University Prof. Jan Vitek Tomas Kalibera Petr Maj Lei Zhao T. U. Dortmund Prof. Peter Marwedel Helena KoPhaus Ingo Korb University of California, Davis Prof. Duncan Temple Lang Nicholas Ulle University of Lugano, Switzerland Prof. Walter Binder Sun Haiyang Yudi Zheng Oracle Interns Brian Belleville Miguel Garcia Shams Imam Alexey Karyakin Stephen Kell Andreas Kun… Volker Lan?ng Gero Leinemann Julian LePner Joe Nash David Piorkowski Gregor Richards Robert Seilbeck Rifat Shariyar Alumni Erik Eckstein Michael Haupt Christos Kotselidis Hyunjin Lee David Leibs Chris Thalinger Till Westmann