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

Guilt Free Ruby on the JVM

Chris Seaton
September 15, 2015

Guilt Free Ruby on the JVM

At JavaOne. 2015.

Chris Seaton

September 15, 2015
Tweet

More Decks by Chris Seaton

Other Decks in Research

Transcript

  1. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Faster Ruby and JavaScript with GraalVM Chris Seaton Research Manager Oracle Labs September 20, 2016
  2. 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 information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. Oracle reserves the right to alter its development plans and practices at any time, and the development, release, and timing of any features or functionality described in connection with any Oracle product or service remains at the sole discretion of Oracle. Any views expressed in this presentation are my own and do not necessarily reflect the views of Oracle.
  3. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | The One VM Concept High performance polyglot virtual machine
  4. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | 6 The Ruby Logo is Copyright (c) 2006, Yukihiro Matsumoto. It is licensed under the terms of the Creative Commons Attribution-ShareAlike 2.5 agreement JS Logo Copyright (c) 2011 Christopher Williams <[email protected]>, MIT licence You can distribute the R logo under the terms of the Creative Commons Attribution-ShareAlike 4.0 International license (CC-BY-SA 4.0) or (at your option) the GNU General Public License version 2 (GPL-2).
  5. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Completeness Oracle Confidential – Internal ECMAScript 2015 (ES6) • Graal passes 99.3% (16298 of 16417 tests) • Failing tests are to a large part Unicode Regular Expressions ECMAScript 2016 (ES7) • Graal passes 93.4% (20785 of 22260 tests) • V8 (5.4.500.6) passes 91.1% • Graal supports ES7 (exponentiation operator, Array.prototype.includes) • Fails due to new block-level function declaration and corner-case tests of the spread operator
  6. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Classic research benchmarks – roughly level with V8 Oracle Confidential – Internal 0 0.2 0.4 0.6 0.8 1 1.2 1.4 V8 (5.4.500.6) Graal.js
  7. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Completeness – language and core library Oracle Confidential – Internal Ruby language JRuby passes 94% 96% Ruby core library JRuby passes 95% 99%
  8. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Completeness – the basic Rails stack Oracle Confidential – Internal Active Model Active Support Active Record Action View Action Pack Action Mailer Railties Sprockets-Rails Active Job Spring 100% 100% 98% Basic functionality works 37%
  9. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Classic research benchmarks – 10-20x faster Confidential – Oracle Internal/Restricted/Highly Restricted 17 0 5 10 15 20 25 30 35 40 45 Speedup Compared to Ruby GraalVM JRuby+invokedynamic Ruby Benchmarks bound by allocation or BigInteger performance
  10. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | ‘But it’s easy to optimise that kind of code!’ Confidential – Oracle Internal/Restricted/Highly Restricted 18
  11. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Confidential – Oracle Internal/Restricted/Highly Restricted 19 Simple local variables Vectorisation opportunities Simple floating point arithmetic Basic loops No method calls (except operators) Only types are numerical or boolean
  12. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | ‘Real Ruby is much more complex!’ Confidential – Oracle Internal/Restricted/Highly Restricted 20
  13. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Confidential – Oracle Internal/Restricted/Highly Restricted 21 Smalltalk-style blocks instead of loops Loop bounds are objects instead of simple values Instance variables Logic hidden in methods Arrays
  14. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Confidential – Oracle Internal/Restricted/Highly Restricted 22 Arithmetic hidden in core library methods Intermediate objects Hash mapped to an array of arrays, via another array, converted back to a hash Inner loop pixels represented as a hash of r, g, b No local variables, only method calls
  15. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Confidential – Oracle Internal/Restricted/Highly Restricted 23 Metaprogramming send Dynamically created symbol Actual logic method dynamic method calls
  16. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Chunky PNG kernels Confidential – Oracle Internal/Restricted/Highly Restricted 24 0.01 0.1 1 10 100 1000 Speedup Compared to Ruby GraalVM JRuby+invokedynamic Ruby Many of these benchmarks are optimised away entirely by GraalVM
  17. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | PSD.rb kernels Confidential – Oracle Internal/Restricted/Highly Restricted 25 0.1 1 10 100 1000 Speedup Compared to Ruby GraalVM JRuby+invokedynamic Ruby JRuby is sometimes slower than Ruby
  18. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | REST public internet REST private intranet
  19. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Warms up and then reports iterations per second Random inputs stop the whole thing being totally optimised away
  20. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | clamp in Ruby 0 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 GraalVM JRuby+invokedynamic Ruby Operations Per Second
  21. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | clamp in Ruby 0 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 GraalVM JRuby+invokedynamic Ruby Operations Per Second This is what GraalVM is giving you for Ruby before we even start talking about JavaScript
  22. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Not only have we rewritten in JavaScript, but the JavaScript code is simpler than the Ruby
  23. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | clamp in Ruby and JavaScript with V8 0 50000 100000 150000 200000 250000 300000 350000 Ruby (just Ruby) Ruby (Ruby + JS with V8) Operations Per Second
  24. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | clamp in Ruby and JavaScript with JRuby and Rhino 0 100000 200000 300000 400000 500000 600000 JRuby+indy (just Ruby) JRuby+indy (Ruby + JS with Rhino) Operations Per Second
  25. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | clamp in Ruby and JavaScript with JRuby and Nashorn 0 100000 200000 300000 400000 500000 600000 JRuby+indy (just Ruby) JRuby+indy (Ruby + JS with Rhino) JRuby+indy (Ruby + JS with Nashorn) Operations Per Second
  26. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | clamp in Ruby and JavaScript with GraalVM 0 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 GraalVM (just Ruby) GraalVM (Ruby + JS) JRuby+invokedynamic Ruby Operations Per Second
  27. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | clamp in all configurations 0 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 GraalVM (just Ruby) GraalVM (Ruby + JS) JRuby+indy (just Ruby) JRuby+indy (Ruby + JS with Rhino) JRuby+indy (Ruby + JS with Nashorn) Ruby (just Ruby) Ruby (Ruby + JS with V8) Operations Per Second
  28. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | clamp in all configurations 1 10 100 1000 10000 100000 1000000 10000000 GraalVM (just Ruby) GraalVM (Ruby + JS) JRuby+indy (just Ruby) JRuby+indy (Ruby + JS with Rhino) JRuby+indy (Ruby + JS with Nashorn) Ruby (just Ruby) Ruby (Ruby + JS with V8) Operations Per Second
  29. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | • Common representation of programs • Keep it rich enough to not have to throw away meaning • Common optimisation of the representation
  30. 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
  31. 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
  32. 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
  33. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | U U U U U Node Rewriting for Profiling Feedback AST Interpreter Uninitialized Nodes 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.
  34. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | U U U U U I I I G G Node Rewriting for Profiling Feedback AST Interpreter Rewritten Nodes AST Interpreter Uninitialized Nodes 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.
  35. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | I I I G G I I I G G Rewriting ng Feedback AST Interpreter Rewritten Nodes Compilation using Partial Evaluation Compiled Code I D Uninitialized Integer Generic Double 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.
  36. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | 74 codon.com/compilers-for-free Presentation, by Tom Stuart, licensed under a Creative Commons Attribution ShareAlike 3.0
  37. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | 20/09/2016 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 Node Rewriting to Update Profiling Feedback
  38. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | 20/09/2016 Oracle Confidential – Internal/Restricted/Highly Restricted 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 G G D I D G G D I D G G Node Rewriting to Update Profiling Feedback Recompilation using Partial Evaluation
  39. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | GraalVM – everything in one package today • Includes: – JVM (RE or DK) – Java – JavaScript – Ruby – R – More in the future • Binary tarball release • Mac or Linux
  40. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Java 9 – runs on an unmodified JVM Hotspot Graal Truffle JS others… R Java C++ JVMCI (JVM Compiler Interface)
  41. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Java 9 – runs on an unmodified JVM Hotspot Graal Truffle JS others… Ruby via Maven etc Java 9
  42. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Search for ’graal otn’ www.oracle.com/technetwork/oracle-labs/program-languages
  43. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Search for ‘github graalvm’ github.com/graalvm
  44. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Search for ‘github jruby’ github.com/jruby/jruby
  45. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Polyglot on the JVM with Graal [CON4553] Tuesday, Sep 20, 5:30 p.m. - 6:30 p.m. Hilton - Plaza Room A
  46. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Acknowledgements Oracle Danilo Ansaloni Stefan Anzinger Cosmin Basca Daniele Bonetta Matthias Brantner Petr Chalupa Jürgen Christ Laurent Daynès Gilles Duboscq Martin Entlicher Brandon Fish Bastian Hossbach Christian Humer Mick Jordan Vojin Jovanovic Peter Kessler David Leopoldseder Kevin Menard Jakub Podlešák Aleksandar Prokopec Tom Rodriguez Oracle (continued) 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 Christian Wimmer Christian Wirth Paul Wögerer Mario Wolczko Andreas Wöß Thomas Würthinger JKU Linz Prof. Hanspeter Mössenböck Benoit Daloze Josef Eisl Thomas Feichtinger Matthias Grimmer Christian Häubl Josef Haider Christian 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 Kotthaus 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 Kunft Volker Lanting Gero Leinemann Julian Lettner 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
  47. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.

    | Safe Harbor Statement The preceding is intended to provide some insight into a line of research in Oracle Labs. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. Oracle reserves the right to alter its development plans and practices at any time, and the development, release, and timing of any features or functionality described in connection with any Oracle product or service remains at the sole discretion of Oracle. Any views expressed in this presentation are my own and do not necessarily reflect the views of Oracle.