Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Scala ♥ Graal by Flavio Brasil

34 views

Published on

on June 28th at ScalaMatsuri 2019
http://2019.scalamatsuri.org/index_en.html

Published in: Software
  • Be the first to comment

  • Be the first to like this

Scala ♥ Graal by Flavio Brasil

  1. 1. Flavio W. Brasil @flaviowbrasil Twitter, VM Team Scala ❤ Graal
  2. 2. #TwitterVMTeam
  3. 3. Scala’s performance challenges Why Twitter adopted Graal New optimizations 1 #Deploy 2 #Profile 3 #Optimize Agenda
  4. 4. #Deploy Why Twitter adopted Graal
  5. 5. What is Graal?
  6. 6. Graal != GraalVM
  7. 7. Graal != GraalVM
  8. 8. What is a JIT compiler?
  9. 9. Source code
  10. 10. Source code Bytecode
  11. 11. Source code Bytecode Native
  12. 12. Performance Ease of change Why Graal
  13. 13. C2 is a 20yo codebase in C++
  14. 14. Graal is much easier to change
  15. 15. #Profile Scala’s performance challenges
  16. 16. Scala is not Java (but Java is becoming Scala)
  17. 17. Composable APIs Scala’s performance nightmare
  18. 18. Composable APIs are interpreted languages
  19. 19. Why does a single indirection have this effect?
  20. 20. 👍
  21. 21. 😕
  22. 22. Interpreted languages are difficult to optimize
  23. 23. Embedded Interpreted languages are even more difficult to optimize
  24. 24. #Optimize New optimizations by the #TwitterVMTeam
  25. 25. First target: Future
  26. 26. Synchronization
  27. 27. Opaque
  28. 28. CAS Virtualization https://github.com/oracle/graal/pull/636
  29. 29. Q4/2018 Results
  30. 30. * Includes code changes https://github.com/twitter/util/commit/3245a8 -16% alloc/s-5% CPU CAS Optimizations (regular load)
  31. 31. All optimizations (stress test)
  32. 32. All optimizations (stress test)
  33. 33. All optimizations (stress test)
  34. 34. Second target: itable stub calls
  35. 35. What is an itable stub?
  36. 36. Virtual call
  37. 37. Virtual call
  38. 38. Virtual call
  39. 39. Virtual call Object getClass 1 toString 2
  40. 40. Virtual call Object getClass 1 toString 2 Mammal getClass 1 toString 2
  41. 41. Virtual call Object getClass 1 toString 2 Mammal getClass 1 toString 2 speak 3
  42. 42. Virtual call Object getClass 1 toString 2 Mammal getClass 1 toString 2 speak 3 Human getClass 1 toString 2 speak 3
  43. 43. Virtual call Object getClass 1 toString 2 Mammal getClass 1 toString 2 speak 3 Human getClass 1 toString 2 speak 3 speak(String) 4
  44. 44. Interface call
  45. 45. Interface call
  46. 46. Interface call
  47. 47. Interface call Human Named 1 Mammal 2
  48. 48. Interface call Human Named 1 Mammal 2 Human/ Mammal speak 2 Human/ Named name 1
  49. 49. Interface call Human Named 1 Mammal 2 Human/ Mammal speak 2 Human/ Named name 1 ❓
  50. 50. Interface call Human Named 1 Mammal 2 Human/ Mammal speak 2 Human/ Named name 1 ❌
  51. 51. Interface call Human Named 1 Mammal 2 Human/ Mammal speak 2 Human/ Named name 1 ❌ ❓
  52. 52. Interface call Human Named 1 Mammal 2 Human/ Mammal speak 2 Human/ Named name 1 ❌ ✅
  53. 53. Interface call Human Named 1 Mammal 2 Human/ Mammal speak 2 Human/ Named name 1 ❌ ✅ ✅
  54. 54. How can we optimize it?
  55. 55. Data-driven approach
  56. 56. Top invokes
  57. 57. Common offsets
  58. 58. Common offsets
  59. 59. Top invokes Common offsets
  60. 60. What if a new class is observed?
  61. 61. Call A B
  62. 62. Call A B C
  63. 63. Deoptimization is challenging
  64. 64. Single method
  65. 65. Common super class
  66. 66. Fingerprint
  67. 67. Q1/2019 Initial results
  68. 68. Invoke interface optimization (stress test) Max RPS Max QPS Baseline 735 3762 Optimized 1349 4548 Improvement 83% 20%
  69. 69. Before After Invoke interface optimization (stress test)
  70. 70. Before After
  71. 71. Performance ✅ Ease of change ✅ Why Graal
  72. 72. Thank you!

×