groovy, gpars, @compilestatic and invokedynamic. and java 8

37
Copyright © 2014 Russel Winder 1 Groovy, GPars, @CompileStatic and invokedynamic. And Java 8. Russel Winder email: [email protected] xmpp: [email protected] twitter: @russel_winder http://www.russel.org.uk

Upload: russel-winder

Post on 29-Nov-2014

1.217 views

Category:

Technology


3 download

DESCRIPTION

The beginnings of an investigation into the benefit of @CompileStatic and invokedynamic for CPU-bound Groovy codes. This is the slide set for my Greach2014 talk. Code in my Pi_Quadrature repository on GitHub: https://github.com/russel/Pi_Quadrature

TRANSCRIPT

Page 1: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

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

Page 2: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 2

is a programming language.

Page 3: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 3

is a dynamic programming language.

Page 4: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 4

Dynamic language rarely

exhibit high performance.

Page 5: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 5

This is generally not a problem as

most dynamic languages are

usually used in I/O-bound contexts.

Page 6: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 6

In CPU-bound contexts however,

it is a REAL problem.

Page 7: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 7

The biggest issue for Groovy performance

is that floating point values are

BigDecimal by default.

Page 8: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 8

We need an example.

Page 9: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 9

Page 10: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 10

What is the Value of ?

Easy, it's known exactly.

It's .

Obviously.

Page 11: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

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.

Page 12: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

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

Page 13: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

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.

Page 14: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 14

Because addition is commutative and

associative, expression can be

decomposed into sums of partial sums.

Page 15: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 15

a + b + c + d + e + f

=

( a + b ) + ( c + d ) + ( e + f )

Page 16: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 16

Scatter – Gather

map reduce

fork join

Data parallel

Page 17: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 17

Back to the BigDecimal issue…

Page 18: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 18

…to the code:

Page 19: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 19

As with (almost) all programming language,

Groovy is focussed on sequential activity.

Page 20: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 20

In a multicore world, we harness all the

cores to improve performance.

Page 21: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 21

The Java Platform offers threads,

Java, and hence Groovy, can use them.

Page 22: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 22

Shared memory multithreading is an

infrastructure technique.

Page 23: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 23

java.util.concurrent

Page 24: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 24

Page 25: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 25

Concurrency can be used for

I/O-bound systems, but…

Page 26: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 26

…concurrency can also be used

for CPU-bound systems.

Parallelism .

Page 27: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 27

Parallelism is about performance.

Page 28: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 28

Look at some code…

Page 29: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 29

Dynamism and parallelism are

rarely good bedfellows.

Page 30: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 30

@CompileStatic is about…

…eliding dynamism.…about performance.

Page 31: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 31

invokedynamic is about…

…supporting dynamism.…performance.

Page 32: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 32

Java 8

The greatest revolution ofJava since 1994.

A far bigger revolution ofJava than Java 5.

Page 33: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 33

Java 8

Introduces various things, the most important of which are:

Lambda expressions.Default methods in interfaces.

Page 34: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 34

Java 8

as a consequence oflambda expressions introduces:

Streams†.

† And parallelism, and parallelism is about performance.

Page 35: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 35

More codes…

Page 36: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

Copyright © 2014 Russel Winder 36

Needs You…

Page 37: Groovy, GPars, @CompileStatic and invokedynamic. And Java 8

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