Communicating Event-Loop Languages similar to E and AmbientTalk are recently gaining more traction as a subset of actor languages. With the rise of JavaScript, E’s notion of vats and non-blocking communication based on promises entered the mainstream. For implementations, the combination of dynamic typing, asynchronous message sending, and promise resolution pose new optimization challenges.
This paper discusses these challenges and presents initial experiments for a Newspeak implementation based on the Truffle framework. Our implementation is on average 1.65x slower than Java on a set of 14 benchmarks. Initial optimizations improve the performance of asynchronous messages and reduce the cost of encapsulation on microbenchmarks by about 2x. Parallel actor benchmarks further show that the system scales based on the workload characteristics. Thus, we conclude that Truffle is a promising platform also for communicating event-loop languages.
HTML Injection Attacks: Impact and Mitigation Strategies
Optimizing Communicating Event-Loop Languages with Truffle
1. Stefan Marr, Hanspeter Mössenböck
AGERE! Workshop
October 26, 2015
Optimizing
Communicating Event-Loop
Languages with Truffle
Research funded by
NS
2. Initial Goals
• Safety
– Guaranteed Isolation
– No Low-Level Data Races
• Deadlock Freedom
• Performance Competitive with Java
2
NS: A Platform For Concurrency Research
8. public class PingPong new = Benchmark <: Value (
class Ping new: cnt with: pongAct = (
private pingsLeft ::= cnt. (* mutable slot *)
private pongAct = pongAct. (* immutable slot *)
)(
8
Newspeak
A Class-based Language
Dynamically Typed
No Global/Static State
9. public class PingPong new = Benchmark <: Value (
class Ping new: cnt with: pongAct = (
private pingsLeft ::= cnt. (* mutable slot *)
private pongAct = pongAct. (* immutable slot *)
)(
9
Newspeak
public ping = (
pongAct <-: ping: self.
pingsLeft := pingsLeft - 1.
)
Communicating Event-Loop Actors
10. public class PingPong new = Benchmark <: Value (
class Ping new: cnt with: pongAct = (
private pingsLeft ::= cnt. (* mutable slot *)
private pongAct = pongAct. (* immutable slot *)
)(
10
Newspeak
Newspeak Programming Language Draft
Specification Version 0.095
http://bracha.org/newspeak-spec.pdf
With Spec:
public ping = (
pongAct <-: ping: self.
pingsLeft := pingsLeft - 1.
)
11. : Built on Truffle
11
cnt
1
+
cnt:
=
if
cnt:
=
0
cnt
1
+
cnt:
=if cnt:
=
0
NS
Truffle’s Self-Optimization Approach:
[1] Würthinger, T.; Wöß, A.; Stadler, L.; Duboscq, G.; Simon, D. & Wimmer, C. (2012),
Self-Optimizing AST Interpreters, Proceedings of the 8th Dynamic Languages Symposium.
JIT Compiled
Native Code
Self-Optimized AST
12. : A Fast Newspeak
12
NS
SOMNS versus Java (Graal Compiler)
On average 1.65x slower (min. −3%, max. 2.6x)
0.0
0.5
1.0
1.5
2.0
2.5
3.0
Bounce
BubbleSort
DeltaBlue
Fannkuch
Json
Mandelbrot
NBody
PageRank
Permute
Queens
QuickSort
Richards
Sieve
Storage
Runtimefactornormalized
toJava
RuntimeFactor
NormalizedtoJava
Lower
Is
Better
13. vs. JVM Actor Libraries
13
NS
Chameneos
ConcurrentSorted
LinkedList
Counting ForkJoinThroughput PingPong RadixSort ThreadRing Geo Mean
0
1
2
3
4
5
6
7
8
RuntimefactoroverScalaz
lowerisbetter
Akka Jetlang SOMns Scalaz
RuntimeFactor
NormalizedtoScalaz
Lower
Is
Better
Savina Benchmarks
[2] Imam, S. M. & Sarkar, V. (2014), Savina - An Actor Benchmark
Suite: Enabling Empirical Evaluation of Actor Libraries, Proceedings of
the 4th AGERE! Workshop, ACM.
21. Impact on Microbenchmarks
21
Speedup Factor over Unoptimized Version
public class With10Args new = Benchmark (
private aValue = Value new.
private obj ::= Object new.
public benchmark = (
self <-: a1: aValue a2: Object new a3: obj
a4: Benchmark a5: aValue
a6: 0 a7: 7 a8: 8 a9: #eee a0: '33'.
) )
with 10
arguments
1.0 1.5 2.0 2.5 3.0
Benchmark
22. Method Lookup for Asynchronous Sends
22
A1
Event-Loop: Single Point of Reception
B
A2
C
do
get
set
do
a1 <-: do
b <-: get
a2 <-: set
c <-: do
Megamorphic Method Invocations
while (true) {
msg = mailbox.receive()
mthd = msg.obj.getClass().
lookup(msg.selector())
mthd.invoke(obj, msg.args)
}
24. With Send-site Caching
24
A1
B
A2
C
do
get
set
do
a1 <-: do
b <-: get
a2 <-: set
c <-: do
while (true) {
msg = mailbox.receive()
msg.fun.
invoke(obj, msg.args)
}fun1(.) {…}
fun2(.) {…}
fun3(.) {…}
fun4(.) {…}
25. Impact on Microbenchmarks
25
Speedup Factor over Unoptimized Version
public count = (
cnt := cnt + 1.
cnt = iterations
ifTrue: [ completionPP resolve: cnt ]
ifFalse: [ self <-: count ]
)
lookup in cls
lookup in
5th supercls
1.0 1.5 2.0 2.5 3.0
Benchmark
26. Impact on Microbenchmarks
26
Speedup Factor over Unoptimized Version
public calc: a and: b = (
| r |
r := a * b + b + b – a.
r := r - (a * a * b).
^ r
)
lookup in cls
lookup in
5th supercls
with
int or double
1.0 1.5 2.0 3.0 10.0 50.0 100.0
Benchmark
lookup in cls
lookup in
5th supercls
with
int or double
1.0 1.5 2.0 3.0 10.0 50.0 100.0
Benchmark
public benchmark = (
1 to: numIter do: [:i |
self <-: calc: 2 and: 4.
self <-: calc: 1.2 and: 3.3.
].
)
27. : Fast And Scalable
• Platform for Concurrency Research
• Initial optimizations
– Send-site Caching + Isolation 27
NS
Chameneos
ConcurrentSorted
LinkedList
Counting ForkJoinThroughput PingPong RadixSort ThreadRing Geo Mean
0
1
2
3
4
5
6
7
8
RuntimefactoroverScalaz
lowerisbetter
Akka Jetlang SOMns ScalazLower
Is
Better
RuntimeFactor
NormalizedtoScalaz
Hinweis der Redaktion
Talk: 18min + 5min questions
Can safe actor languages be efficient & usable enough for complex concurrent applications?