Upload
others
View
15
Download
0
Embed Size (px)
Citation preview
Flavio W. Brasil@flaviowbrasilTwitter, VM Team
Scala ❤ Graal
#TwitterVMTeam
Desafios de performance em Scala
Porque o Twitter decidiu usar o Graal
Novas otimizações
1 #Deploy 2 #Profile 3 #Optimize
Agenda
#DeployPorque 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
PerformanceFacilidade de mudança
Porque Graal
C2 é uma base de código de 20 anos em C++
É muito mais fácil trabalhar no Graal
#ProfileDesafios de performance em Scala
Scala não é Java(mas Java está virando Scala)
Composable APIsO 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
#OptimizeNovas otimizações do #TwitterVMTeam
Primeira otimização: Future
Sincronização
Opaque
CAS Virtualizationhttps://github.com/oracle/graal/pull/636
Q4/2018Resultados
* Inclui mudanças de códigohttps://github.com/twitter/util/commit/3245a8
-16% alloc/s-5% CPU
CAS Optimizations(regular load)
All optimizations(stress test)
All optimizations(stress test)
All optimizations(stress test)
Próxima otimização: itable stub calls
O que sãoitable 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
toString 2
Mammal
getClass 1
toString 2
speak 3
Human
getClass 1
toString 2
speak 3
Virtual call
Object
getClass 1
toString 2
Mammal
getClass 1
toString 2
speak 3
Human
getClass 1
toString 2
speak 3
speak(String) 4
Interface call
Interface call
Interface call
Interface call
Human
Named 1
Mammal 2
Interface call
Human
Named 1
Mammal 2Human/Mammal
speak 2
Human/Named
name 1
Interface call
Human
Named 1
Mammal 2Human/Mammal
speak 2
Human/Named
name 1
❓
Interface call
Human
Named 1
Mammal 2Human/Mammal
speak 2
Human/Named
name 1
❌
Interface call
Human
Named 1
Mammal 2Human/Mammal
speak 2
Human/Named
name 1
❌
❓
Interface call
Human
Named 1
Mammal 2Human/Mammal
speak 2
Human/Named
name 1
❌
✅
Interface call
Human
Named 1
Mammal 2Human/Mammal
speak 2
Human/Named
name 1
❌
✅
✅
Como otimizar?
Abordagem data-driven
Top invokes
Common offsets
Common offsets
Top invokes Com common offsets
E se uma nova classe é observada?
Call
A
B
Call
A
B
C
Deoptimizationé difícil
Single method
Common super class
Fingerprint
Q1/2019Resultados iniciais
Invoke interface optimization(teste de stress)
Max RPS Max Capacity
Baseline 735 3762
Optimized 1349 4548
Improvement 83% 20%
Antes Depois
Invoke interface optimization(teste de stress)
Antes
Depois
Performance ✅ Facilidade de mudança ✅
Porque Graal
Obrigado!