Вы находитесь на странице: 1из 122

Scala ❤ Graal

Flavio W. Brasil
@flaviowbrasil
Twitter, VM Team
#TwitterVMTeam
Agenda

1 #Deploy 2 #Profile 3 #Optimize

Porque o Twitter Desafios de


Novas
decidiu usar o performance em
otimizações
Graal Scala
#Deploy
Porque o Twitter decidiu usar o Graal
O que é o Graal?
Graal != GraalVM
Graal != GraalVM
O que é um JIT Compiler?
Código fonte
Código fonte Bytecode
Código fonte Bytecode Nativo
Porque Graal

Performance
Facilidade de mudança
C2 é uma base de código
de 20 anos em C++
É muito mais fácil
trabalhar no Graal
#Profile
Desafios de performance em Scala
Scala não é Java
(mas Java está virando Scala)
Composable APIs
O pesadelo de performance em Scala
Composable APIs são
linguagens interpretadas
Porque uma simples
indireção tem esse efeito?
👍
😕
Linguagens interpretadas
são difíceis de otimizar
#Optimize
Novas otimizações do #TwitterVMTeam
Primeira otimização:
Future
Sincronização
Opaque
CAS Virtualization
https://github.com/oracle/graal/pull/636
Q4/2018
Resultados
CAS Optimizations
(regular load)

-5% CPU -16% alloc/s

* Inclui mudanças de código


https://github.com/twitter/util/commit/3245a8
All optimizations
(stress test)
All optimizations
(stress test)
All optimizations
(stress test)
Próxima otimização:
itable stub calls
O que são
itable stubs?
Virtual call
Virtual call
Virtual call
Virtual call

Object

getClass 1

toString 2
Virtual call

Object

getClass 1

toString 2

Mammal

getClass 1

toString 2
Virtual call

Object

getClass 1

toString 2

Mammal

getClass 1

toString 2

speak 3
Virtual call

Object

getClass 1 Human

toString 2 getClass 1

toString 2
Mammal
speak 3
getClass 1

toString 2

speak 3
Virtual call

Object

getClass 1 Human

toString 2 getClass 1

toString 2
Mammal
speak 3
getClass 1
speak(String) 4
toString 2

speak 3
Interface call
Interface call
Interface call
Interface call

Human

Named 1

Mammal 2
Interface call

Human/
Named
Human name 1
Named 1

Mammal 2
Human/
Mammal

speak 2
Interface call

Human/
Named
Human name 1
❓ Named 1

Mammal 2
Human/
Mammal

speak 2
Interface call

Human/
Named
Human name 1
❌ Named 1

Mammal 2
Human/
Mammal

speak 2
Interface call

Human/
Named
Human name 1
❌ Named 1

❓ Mammal 2
Human/
Mammal

speak 2
Interface call

Human/
Named
Human name 1
❌ Named 1

✅ Mammal 2
Human/
Mammal

speak 2
Interface call

Human/
Named
Human name 1
❌ Named 1

✅ Mammal 2
Human/
Mammal

✅ speak 2
Como otimizar?
Abordagem data-driven
Top invokes
Common offsets
Common offsets
Top invokes Com common offsets
E se uma nova
classe é observada?
A

Call B
A

Call B

C
Deoptimization
é difícil
Single method
Common super class
Fingerprint
Q1/2019
Resultados iniciais
Invoke interface optimization
(teste de stress)

Max RPS Max Capacity

Baseline 735 3762

Optimized 1349 4548

Improvement 83% 20%


Invoke interface optimization
(teste de stress)

Antes Depois
Antes

Depois
Porque Graal

Performance ✅
Facilidade de mudança ✅
Obrigado!

Вам также может понравиться