Copyright © 2014 Russel Winder 1
Groovy, GPars, @CompileStatic and invokedynamic. And Java 8.
Russel Winder
email: [email protected]: [email protected]
twitter: @russel_winder
http://www.russel.org.uk
Copyright © 2014 Russel Winder 2
is a programming language.
Copyright © 2014 Russel Winder 3
is a dynamic programming language.
Copyright © 2014 Russel Winder 4
Dynamic language rarely
exhibit high performance.
Copyright © 2014 Russel Winder 5
This is generally not a problem as
most dynamic languages are
usually used in I/O-bound contexts.
Copyright © 2014 Russel Winder 6
In CPU-bound contexts however,
it is a REAL problem.
Copyright © 2014 Russel Winder 7
The biggest issue for Groovy performance
is that floating point values are
BigDecimal by default.
Copyright © 2014 Russel Winder 8
We need an example.
Copyright © 2014 Russel Winder 9
Copyright © 2014 Russel Winder 10
What is the Value of ?
Easy, it's known exactly.
It's .
Obviously.
Copyright © 2014 Russel Winder 11
Putative joke involving Alexander Orlov (*)and the phrase It's simples. elided as UK“ ”television-related comedy doesn't travel.
(*) A fairly cute meerkat.
Copyright © 2014 Russel Winder 12
Approximating
● What is it's value represented as a floating point number?● We can only obtain an approximation.● A plethora of possible algorithms to choose from, a
popular one is to employ the following integral equation.
4=∫0
1 1
1x2dx
Copyright © 2014 Russel Winder 13
One Possible Algorithm
● Use quadrature to estimate the value of the integral – which is the area under the curve.
=4n∑i=1
n 1
1i−0.5n
2
With n = 3 not much to do, but potentially lots of error. Use n = 107 or n = 109?
Embarrassingly parallel.
Copyright © 2014 Russel Winder 14
Because addition is commutative and
associative, expression can be
decomposed into sums of partial sums.
Copyright © 2014 Russel Winder 15
a + b + c + d + e + f
=
( a + b ) + ( c + d ) + ( e + f )
Copyright © 2014 Russel Winder 16
Scatter – Gather
map reduce
fork join
Data parallel
Copyright © 2014 Russel Winder 17
Back to the BigDecimal issue…
Copyright © 2014 Russel Winder 18
…to the code:
Copyright © 2014 Russel Winder 19
As with (almost) all programming language,
Groovy is focussed on sequential activity.
Copyright © 2014 Russel Winder 20
In a multicore world, we harness all the
cores to improve performance.
Copyright © 2014 Russel Winder 21
The Java Platform offers threads,
Java, and hence Groovy, can use them.
Copyright © 2014 Russel Winder 22
Shared memory multithreading is an
infrastructure technique.
Copyright © 2014 Russel Winder 23
java.util.concurrent
Copyright © 2014 Russel Winder 24
Copyright © 2014 Russel Winder 25
Concurrency can be used for
I/O-bound systems, but…
Copyright © 2014 Russel Winder 26
…concurrency can also be used
for CPU-bound systems.
Parallelism .
Copyright © 2014 Russel Winder 27
Parallelism is about performance.
Copyright © 2014 Russel Winder 28
Look at some code…
Copyright © 2014 Russel Winder 29
Dynamism and parallelism are
rarely good bedfellows.
Copyright © 2014 Russel Winder 30
@CompileStatic is about…
…eliding dynamism.…about performance.
Copyright © 2014 Russel Winder 31
invokedynamic is about…
…supporting dynamism.…performance.
Copyright © 2014 Russel Winder 32
Java 8
The greatest revolution ofJava since 1994.
A far bigger revolution ofJava than Java 5.
Copyright © 2014 Russel Winder 33
Java 8
Introduces various things, the most important of which are:
Lambda expressions.Default methods in interfaces.
Copyright © 2014 Russel Winder 34
Java 8
as a consequence oflambda expressions introduces:
Streams†.
† And parallelism, and parallelism is about performance.
Copyright © 2014 Russel Winder 35
More codes…
Copyright © 2014 Russel Winder 36
Needs You…
Copyright © 2014 Russel Winder 37
Groovy, GPars, @CompileStatic and invokedynamic. And Java 8
Russel Winder
email: [email protected]: [email protected]
twitter: @russel_winder
http://www.russel.org.uk
Top Related