SlideShare a Scribd company logo
The Quantum Physics
of Java
Michael Heinrichs
Canoo Engineering AG
for (int i = 0; i < n; i++) {
a[i] *= 3;
}
for (int i = 0; i < n; i+=16) {
a[i] *= 3;
} 26,1 ms
25,8 ms
Michael Heinrichs
http://blog.netopyr.com
@net0pyr
canoo
delivering end-user happiness[ ]
for (int i = 0; i < n; i++) {
a[i] *= 3;
}
for (int i = 0; i < n; i+=16) {
a[i] *= 3;
} 26,1 ms
25,8 ms
CPU
Main Memory
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
CPU
CPU
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1
CPU
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3
CPU
3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3
CPU
3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1
CPU
3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3
CPU
3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3
1980 1985 1990 1995 2000 2005 2010
1
10
100
1000
10000
100000
CPU
Memory
Year
Performance
Main Memory
CPU
Main Memory
Cache
CPU
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
CPU
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1
CPU
CPU
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1
1
CPU
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1
3
CPU
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3 1 1 1 1 1
3
CPU
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3 1 1 1 1 1
1
CPU
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3 1 1 1 1 1
3
CPU
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3 3 1 1 1 1
3
for (int i = 0; i < n; i++) {
a[i % a.length] *= 3;
}
1 KB 2 KB 4 KB 8 KB 16 KB 32 KB 64 KB 128 KB 256 KB 512 KB 1 MB 2 MB 4 MB 8 MB 16 MB 32 MB 64 MB 128 MB 256 MB
0
1
2
3
4
5
6
7
CPU
Main Memory
Cache
Main Memory
L1 Cache
L2 Cache
L3 Cache
CPU
1 KB 2 KB 4 KB 8 KB 16 KB 32 KB 64 KB 128 KB 256 KB 512 KB 1 MB 2 MB 4 MB 8 MB 16 MB 32 MB 64 MB 128 MB 256 MB
0
1
2
3
4
5
6
7
Not quite pints
By radioedit (CC BY-SA 2.0)
Main Memory
L1 Cache
L2 Cache
L3 Cache
< 1 ns, 32 KB
7 ns, 256 KB
25 ns, 8 MB
100 ns, 16 GB
CPU
for (int i = 0; i < n; i++) {
a[i % a.length] *= 3;
}
for (int i = 0; i < n; i++) {
a[rnd()] *= 3;
}
1 KB
2 KB
4 KB
8 KB
16 KB
32 KB
64 KB
128 KB
256 KB
512 KB
1 MB
2 MB
4 MB
8 MB
16 MB
32 MB
64 MB
128 MB
256 MB
0
1
2
3
4
5
6
7
1 KB
2 KB
4 KB
8 KB
16 KB
32 KB
64 KB
128 KB
256 KB
512 KB
1 MB
2 MB
4 MB
8 MB
16 MB
32 MB
64 MB
128 MB
256 MB
0
5
10
15
20
25
1 KB
2 KB
4 KB
8 KB
16 KB
32 KB
64 KB
128 KB
256 KB
512 KB
1 MB
2 MB
4 MB
8 MB
16 MB
32 MB
64 MB
128 MB
256 MB
0
5
10
15
20
25
perf
perf stat application
perf stat -p 1234 sleep 5
The Quantum Physics of Java
The Quantum Physics of Java
Main Memory
L1 Cache
L2 Cache
L3 Cache
CPU
1 1 1 1 1 11 1 1 1 11 1 1 1 1
CPU
1 1 1 1 1 11 1 1 1 11 1 1 1 1
1 1 1 1
CPU
CPU
1 1 1 1 1 11 1 1 1 11 1 1 1 1
1 1 1 1
1
CPU
1 1 1 1 1 11 1 1 1 11 1 1 1 1
1 1 1 1
1
1 1 1 1
1 KB
2 KB
4 KB
8 KB
16 KB
32 KB
64 KB
128 KB
256 KB
512 KB
1 MB
2 MB
4 MB
8 MB
16 MB
32 MB
64 MB
128 MB
256 MB
0
5
10
15
20
25
int a;
Thread 1: a++;
Thread 2: return a;
2,1 ops/ns
1,2 ops/ns
Main Memory
L2 Cache
L3 Cache
L1 Cache L1 Cache
Core 1 Core 2
L1 Cache L1 Cachea
Core 1 Core 2
L1 Cache L1 Cachea a
?
Core 1 Core 2
Modified Exclusive
Shared Invalid
Modified Exclusive
Shared Invalid
Modified Exclusive
Shared Invalid
Modified Exclusive
Shared Invalid
Modified Exclusive
Shared Invalid
Modified Exclusive
Shared Invalid
Modified Exclusive
Shared Invalid
L1 Cache L1 Cachea a
Core 1 Core 2
int a;
int b;
Thread 1: a++;
Thread 2: return b;
2,1 ops/ns
1,2 ops/ns
L1 Cache L1 Cachea b
Core 1 Core 2
L1 Cache L1 Cachea ab b
Core 1 Core 2
Given: sorted int[16]
Linear or Binary Search?
21,8 ns 28,2 ns
The Quantum Physics of Java
A
B
C
D
E
CPU
Fetch
A
A
B
C
D
E
Fetch Decode
A
A
B
C
D
E
Fetch Decode Execute
A
A
B
C
D
E
Fetch Decode Execute Write-
back
A
A
B
C
D
E
Fetch Decode Execute Write-
back
A
A
B
C
D
E
Fetch Decode Execute Write-
back
B
A
B
C
D
E A
Fetch Decode Execute Write-
back
C
A
B
C
D
E B A
Fetch Decode Execute Write-
back
D
A
B
C
D
E C B A
Fetch Decode Execute Write-
back
E
A
B
C
D
E D C B
Fetch Decode Execute Write-
back
A
B
C
D
E
Fetch Decode Execute Write-
back
A
B
C
D
E A
Fetch Decode Execute Write-
back
A
B
C
D
E A?
Fetch Decode Execute Write-
back
A
B
C
D
E AB
Fetch Decode Execute Write-
back
A
B
C
D
E C B A
Fetch Decode Execute Write-
back
A
B
C
D
E C B A
Fetch Decode Execute Write-
back
A
B
C
D
E C B A
Fetch Decode Execute Write-
back
A
B
C
D
E AE
Binary Search
while (low <= high)
…
if (midVal < needle)
…
else if (midVal > needle)
…
else
…
Linear Search
for element : haystack
if element == needle
…
else if (element > needle)
…
int a;
int b;
a *= 3;
a *= 5;
a *= 3;
b *= 5;
2,3 ns
2,1 ns
The Quantum Physics of Java
Fetch Decode Execute Write-
back
Fetch Decode Execute Write-
back
Execute
Execute
Fetch Decode Execute Write-
back
Execute
Execute
Fetch
Fetch
Fetch Decode Write-
back
Fetch
Fetch
A
B
C
Execute
Execute
Execute
Fetch Decode Write-
back
Fetch
Fetch
A
B
C
A
B
C
Execute
Execute
Execute
Fetch Decode Write-
back
Fetch
Fetch
A
B C
A
B
C
Execute
Execute
Execute
Fetch Decode Execute Write-
back
Execute
Execute
Fetch
Fetch
A
B
C
A
B
C
Fetch Decode Execute Write-
back
Execute
Execute
Fetch
Fetch
A
B
C
A
B
C
Fetch Decode Execute Write-
back
Execute
Execute
Fetch
Fetch
A
B
C
A
B
C
Fetch Decode Execute Write-
back
Execute
Execute
Fetch
Fetch
A
B
C AB
C
Fetch Decode Execute Write-
back
Execute
Execute
Fetch
Fetch
A
B
C B
C
Fetch Decode Execute Write-
back
Execute
Execute
Fetch
Fetch
A
B
C
C
Fetch Decode Execute Write-
back
Execute
Execute
Fetch
Fetch
A
B
C
C
Fetch Decode Execute Write-
back
Execute
Execute
Fetch
Fetch
A
B
C
a *= 3 a *= 5
a *= 3
b *= 5
int a;
int b;
a *= 3;
a *= 5;
a *= 3;
b *= 5;
Know thy CPU
(because sometimes it matters)
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/ or send a letter
to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

More Related Content

PDF
[OpenInfra Days Korea 2018] (Track 4) - Backend.AI: 오픈소스 머신러닝 인프라 프레임워크
PDF
Low Overhead System Tracing with eBPF
PPTX
The Internet
PPTX
Scheduling in Linux and Web Servers
PDF
Concurrency in Go by Denys Goldiner.pdf
PDF
計算機性能の限界点とその考え方
PDF
Building a DSL with GraalVM (VoxxedDays Luxembourg)
[OpenInfra Days Korea 2018] (Track 4) - Backend.AI: 오픈소스 머신러닝 인프라 프레임워크
Low Overhead System Tracing with eBPF
The Internet
Scheduling in Linux and Web Servers
Concurrency in Go by Denys Goldiner.pdf
計算機性能の限界点とその考え方
Building a DSL with GraalVM (VoxxedDays Luxembourg)

What's hot (20)

PPT
Trelles_QnormBOSC2009
PPTX
Segmentation Faults, Page Faults, Processes, Threads, and Tasks
PDF
Move from C to Go
PDF
Debugging TV Frame 0x0D
PDF
Introduction to RevKit
PPTX
Synchronization
PDF
Reversible Logic Synthesis and RevKit
PPTX
Multi-threading your way out
PDF
Protostar VM - Heap3
PDF
Ntp cheat sheet
PPTX
Ac cuda c_1
PPTX
Developing High Performance Application with Aerospike & Go
PDF
Automatically Fusing Functions on CuPy
PDF
Gameboy emulator in rust and web assembly
PPTX
Streams for the Web
PDF
Goroutine stack and local variable allocation in Go
DOCX
Basic command for linux
PPTX
Multicloud connectivity using OpenNHRP
PDF
Rubinius @ RubyAndRails2010
PDF
Практический опыт профайлинга и оптимизации производительности Ruby-приложений
Trelles_QnormBOSC2009
Segmentation Faults, Page Faults, Processes, Threads, and Tasks
Move from C to Go
Debugging TV Frame 0x0D
Introduction to RevKit
Synchronization
Reversible Logic Synthesis and RevKit
Multi-threading your way out
Protostar VM - Heap3
Ntp cheat sheet
Ac cuda c_1
Developing High Performance Application with Aerospike & Go
Automatically Fusing Functions on CuPy
Gameboy emulator in rust and web assembly
Streams for the Web
Goroutine stack and local variable allocation in Go
Basic command for linux
Multicloud connectivity using OpenNHRP
Rubinius @ RubyAndRails2010
Практический опыт профайлинга и оптимизации производительности Ruby-приложений
Ad

Similar to The Quantum Physics of Java (20)

PDF
Caching in
PDF
Caching in (DevoxxUK 2013)
PDF
Code dive 2019 kamil witecki - should i care about cpu cache
PPTX
M1 rl 1.1.1
PPTX
Computer System Architecture Lecture Note 8.1 primary Memory
PPT
Chapter 5 a
KEY
Locks? We Don't Need No Stinkin' Locks - Michael Barker
KEY
Lock? We don't need no stinkin' locks!
PPT
Memory caching
PPT
Memory caching
PPT
Memory caching
PPT
Memory caching
PPT
Memory caching
PPT
Memory caching
PPTX
Code and memory optimization tricks
PPTX
Code and Memory Optimisation Tricks
PPT
CSE_213_7 Large and Fast Exploiting Memory Hierarchy.ppt
PPTX
Data oriented design and c++
KEY
Everything I Ever Learned About JVM Performance Tuning @Twitter
PDF
Speedup Your Java Apps with Hardware Counters
Caching in
Caching in (DevoxxUK 2013)
Code dive 2019 kamil witecki - should i care about cpu cache
M1 rl 1.1.1
Computer System Architecture Lecture Note 8.1 primary Memory
Chapter 5 a
Locks? We Don't Need No Stinkin' Locks - Michael Barker
Lock? We don't need no stinkin' locks!
Memory caching
Memory caching
Memory caching
Memory caching
Memory caching
Memory caching
Code and memory optimization tricks
Code and Memory Optimisation Tricks
CSE_213_7 Large and Fast Exploiting Memory Hierarchy.ppt
Data oriented design and c++
Everything I Ever Learned About JVM Performance Tuning @Twitter
Speedup Your Java Apps with Hardware Counters
Ad

Recently uploaded (20)

PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
System and Network Administration Chapter 2
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Essential Infomation Tech presentation.pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Nekopoi APK 2025 free lastest update
PPTX
history of c programming in notes for students .pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
System and Network Administraation Chapter 3
PDF
AI in Product Development-omnex systems
PPTX
Introduction to Artificial Intelligence
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
System and Network Administration Chapter 2
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Essential Infomation Tech presentation.pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Odoo Companies in India – Driving Business Transformation.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Wondershare Filmora 15 Crack With Activation Key [2025
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Reimagine Home Health with the Power of Agentic AI​
Nekopoi APK 2025 free lastest update
history of c programming in notes for students .pptx
How Creative Agencies Leverage Project Management Software.pdf
System and Network Administraation Chapter 3
AI in Product Development-omnex systems
Introduction to Artificial Intelligence
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus

The Quantum Physics of Java