high performance managed languages - qcon london … · high performance managed languages martin...

107
High Performance Managed Languages Martin Thompson - @mjpt777

Upload: truongmien

Post on 26-Jul-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

High Performance

Managed Languages

Martin Thompson - @mjpt777

Page 2: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Really, what is your preferred

platform for building HFT

applications?

Page 3: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection
Page 4: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Why do you build low-latency

applications on a

GC’ed platform?

Page 5: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection
Page 6: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

1. Let’s set some Context

2. Runtime Optimisation

3. Garbage Collection

4. Algorithms & Design

Agenda

Page 7: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Some Context

Page 8: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Let’s be clear

A Managed Runtime is not

always the best choice…

Page 9: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Latency Arbitrage?

Page 10: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection
Page 11: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Two questions…

Page 12: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Why build on a

Managed Runtime?

Page 13: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Can managed languages

provide good performance?

Page 14: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

We need to follow the

evidence…

Page 15: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection
Page 16: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Are native languages faster?

Page 17: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Time?

Skills & Resources?

Page 18: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

What can, or should, be

outsourced?

Page 19: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

CPU vs Memory

Performance

Page 20: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

How much time to perform an

addition operation on 2 integers?

Page 21: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

1 CPU Cycle

< 1ns

Page 22: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Sequential Access

-

Average time in ns/op to sum all

longs in a 1GB array?

Page 23: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Access Pattern Benchmark

Benchmark Mode Score Error Units

testSequential avgt 0.832 ± 0.006 ns/op

~1 ns/op

Page 24: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Really???

Less than 1ns per operation?

Page 25: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection
Page 26: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Random walk per OS Page

-

Average time in ns/op to sum all

longs in a 1GB array?

Page 27: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Access Pattern Benchmark

Benchmark Mode Score Error Units

testSequential avgt 0.832 ± 0.006 ns/op

testRandomPage avgt 2.703 ± 0.025 ns/op

~3 ns/op

Page 28: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Data dependant walk per OS Page

-

Average time in ns/op to sum all

longs in a 1GB array?

Page 29: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Access Pattern Benchmark

Benchmark Mode Score Error Units

testSequential avgt 0.832 ± 0.006 ns/op

testRandomPage avgt 2.703 ± 0.025 ns/op

testDependentRandomPage avgt 7.102 ± 0.326 ns/op

~7 ns/op

Page 30: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Random heap walk

-

Average time in ns/op to sum all

longs in a 1GB array?

Page 31: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Access Pattern Benchmark

Benchmark Mode Score Error Units

testSequential avgt 0.832 ± 0.006 ns/op

testRandomPage avgt 2.703 ± 0.025 ns/op

testDependentRandomPage avgt 7.102 ± 0.326 ns/op

testRandomHeap avgt 19.896 ± 3.110 ns/op

~20 ns/op

Page 32: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Data dependant heap walk

-

Average time in ns/op to sum all

longs in a 1GB array?

Page 33: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Access Pattern Benchmark

Benchmark Mode Score Error Units

testSequential avgt 0.832 ± 0.006 ns/op

testRandomPage avgt 2.703 ± 0.025 ns/op

testDependentRandomPage avgt 7.102 ± 0.326 ns/op

testRandomHeap avgt 19.896 ± 3.110 ns/op

testDependentRandomHeap avgt 89.516 ± 4.573 ns/op

~90 ns/op

Page 34: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Then ADD 40+ ns/opfor NUMA access on a server!!!!

Page 35: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Data Dependent Loads

aka “Pointer Chasing”!!!

Page 36: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Performance 101

Page 37: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

1. Memory is transported in Cachelines

Performance 101

Page 38: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

1. Memory is transported in Cachelines

2. Memory is managed in OS Pages

Performance 101

Page 39: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

1. Memory is transported in Cachelines

2. Memory is managed in OS Pages

3. Memory is pre-fetched on

predictable access patterns

Performance 101

Page 40: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Runtime Optimisation

Page 41: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

1. Profile guided optimisations

Runtime JIT

Page 42: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

1. Profile guided optimisations

2. Bets can be taken and later revoked

Runtime JIT

Page 43: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Branches

void foo()

{

// code

if (condition)

{

// code

}

// code

}

Page 44: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Block A

Branches

void foo()

{

// code

if (condition)

{

// code

}

// code

}

Page 45: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Block A

Block B

Branches

void foo()

{

// code

if (condition)

{

// code

}

// code

}

Page 46: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Block A

Block C

Block B

Branches

void foo()

{

// code

if (condition)

{

// code

}

// code

}

Page 47: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Block A

Block C

Block B

Branches

void foo()

{

// code

if (condition)

{

// code

}

// code

}

Block A

Block C

Page 48: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Block A

Block C

Block B

Branches

void foo()

{

// code

if (condition)

{

// code

}

// code

}

Block A

Block C

Block B

Page 49: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Subtle Branches

int result = (i > 7) ? a : b;

Page 50: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Subtle Branches

int result = (i > 7) ? a : b;

CMOV vs Branch Prediction?

Page 51: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Method/Function Inlining

void foo()

{

// code

bar();

// code

}

Page 52: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Method/Function Inlining

void foo()

{

// code

bar();

// code

}

Block A

Page 53: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Method/Function Inlining

void foo()

{

// code

bar();

// code

}

Block A

bar()

Page 54: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Method/Function Inlining

void foo()

{

// code

bar();

// code

}

Block A

bar()

Page 55: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Method/Function Inlining

void foo()

{

// code

bar();

// code

}

Block A

Block B

bar()

Page 56: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Method/Function Inlining

void foo()

{

// code

bar();

// code

}

Block A

Block B

bar()

Block A

Page 57: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Method/Function Inlining

void foo()

{

// code

bar();

// code

}

Block A

Block B

bar()

Block A

bar()

Page 58: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Method/Function Inlining

void foo()

{

// code

bar();

// code

}

Block A

Block B

bar()

Block A

Block B

bar()

Page 59: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Method/Function Inlining

void foo()

{

// code

bar();

// code

}

i-cache

& code bloat?

Page 60: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

“Inlining is THE optimisation.”

- Cliff Click

Method/Function Inlining

Page 61: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Bounds Checking

void foo(int[] array, int length)

{

// code

for (int i = 0; i < length; i++)

{

bar(array[i]);

}

// code

}

Page 62: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Bounds Checking

void foo(int[] array)

{

// code

for (int i = 0; i < array.length; i++)

{

bar(array[i]);

}

// code

}

Page 63: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Subtype Polymorphism

void draw(Shape[] shapes)

{

for (int i = 0; i < shapes.length; i++)

{

shapes[i].draw();

}

}

void bar(Shape shape)

{

bar(shape.isVisible());

}

Page 64: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Subtype Polymorphism

void draw(Shape[] shapes)

{

for (int i = 0; i < shapes.length; i++)

{

shapes[i].draw();

}

}

void bar(Shape shape)

{

bar(shape.isVisible());

}

Class Hierarchy Analysis

& Inline Caching

Page 65: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

1. Profile guided optimisations

2. Bets can be taken and later revoked

Runtime JIT

Page 66: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Garbage Collection

Page 67: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Generational Garbage Collection

“Only the good die young.”

- Billy Joel

Page 68: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Eden Survivor 0 Survivor 1

Young/New Generation

TLA

B

TLA

B

Tenured

Virtual

Virtual

Old Generation

Generational Garbage Collection

Page 69: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Modern Hardware (Intel Sandy Bridge EP)

C 1 C n C 1 C nRegisters/Buffers <1ns

L1 L1 L1 L1~4 cycles ~1ns

L2 L2 L2 L2~12 cycles ~3ns

L3 L3~40 cycles ~15ns

~60 cycles ~20ns (dirty hit)

~65ns

DRAM

QPI ~40nsMC MC

DRAM

DRAM

DRAM

DRAM

DRAM

DRAM

DRAM

...

...

...

...

...

...

QPI QPIPCI-e 3 PCI-e 3

40XIO

40XIO

* Assumption: 3GHz Processor

Page 70: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Broadwell EX – 24 cores & 60MB L3 Cache

Page 71: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Eden

Young/New Generation

TLA

B

TLA

B

Thread Local Allocation Buffers

Page 72: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Eden

Young/New Generation

TLA

B

TLA

B

Thread Local Allocation Buffers

• Affords locality of reference

• Avoid false sharing

• Can have NUMA aware allocation

Page 73: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Eden Survivor 0 Survivor 1

Young/New Generation

TLA

B

TLA

B

Virtual

Object Survival

Page 74: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Eden Survivor 0 Survivor 1

Young/New Generation

TLA

B

TLA

B

Virtual

Object Survival

• Aging Policies

• Compacting Copy

• NUMA Interleave

• Fast Parallel Scavenging

• Only the survivors require work

Page 75: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Eden Survivor 0 Survivor 1

Young/New Generation

TLA

B

TLA

B

Tenured

Virtual

Virtual

Old Generation

Object Promotion

Page 76: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Eden Survivor 0 Survivor 1

Young/New Generation

TLA

B

TLA

B

Tenured

Virtual

Virtual

Old Generation

Object Promotion

• Concurrent Collection

• String Deduplication

Page 77: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Compacting Collections

Page 78: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Compacting Collections – Depth first copy

Page 79: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Compacting Collections

Page 80: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Compacting Collections

OS Pages and

cache lines?

Page 81: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

EdenE

O

S

O

S

O E

S OO

E

O E O O

OSurvivor

Old

Unused

O

S

E

H

Humongous H

H

O O

G1 – Concurrent Compaction

Page 82: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Azul Zing C4

True Concurrent Compacting

Collector

Page 83: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Where next for GC?

Page 84: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Object Inlining/Aggregation

Page 85: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

GC vs Manual Memory Management

Not easy to pick clear winner…

Page 86: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

GC vs Manual Memory Management

Managed GC

• GC Implementation

• Card Marking

• Read/Write Barriers

• Object Headers

• Background Overhead

in CPU and Memory

Not easy to pick clear winner…

Page 87: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

GC vs Manual Memory Management

Managed GC

• GC Implementation

• Card Marking

• Read/Write Barriers

• Object Headers

• Background Overhead

in CPU and Memory

Not easy to pick clear winner…

Native

• Malloc Implementation

• Arena/pool contention

• Bin Wastage

• Fragmentation

• Debugging Effort

• Inter-thread costs

Page 88: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Algorithms & Design

Page 89: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

What is most important to

performance?

Page 90: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

• Avoiding cache misses

• Strength Reduction

• Avoiding duplicate work

• Amortising expensive operations

• Mechanical Sympathy

• Choice of Data Structures

• Choice of Algorithms

• API Design

• Overall Design

Page 91: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

In a large codebase it is really

difficult to do everything well

Page 92: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

It also takes some “uncommon”

disciplines such as:

profiling, telemetry, modelling…

Page 93: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

“If I had more time, I would

have written a shorter letter.”

- Blaise Pascal

Page 94: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

The story of Aeron

Page 95: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Aeron is an interesting lesson in

“time to performance”

Page 96: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Lots of others exists such at the

C# Roslyn compiler

Page 97: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Time spent on

Mechanical Sympathy

vs

Debugging Pointers

???

Page 98: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Immutable Data & Concurrency

Page 99: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Functional Programming

Page 100: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

In Closing …

Page 101: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

What does the future hold?

Page 102: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Remember

Assembly vs Compiled

Languages

Page 103: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

What about the issues of

footprint, startup time,

GC pauses, etc. ???

Page 104: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection
Page 105: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection
Page 106: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection
Page 107: High Performance Managed Languages - QCon London … · High Performance Managed Languages Martin Thompson - @mjpt777. ... - Billy Joel. Eden Survivor 0 ... • Concurrent Collection

Blog: http://mechanical-sympathy.blogspot.com/

Twitter: @mjpt777

“Any intelligent fool can make things bigger, more complex, and more violent.

It takes a touch of genius, and a lot of courage, to move in the opposite direction.”

- Albert Einstein

Questions?