#1BRC | @gunnarmorling
● Software engineer at Decodable
● Former project lead of Debezium
● kcctl 🧸, JfrUnit, ModiTect,
MapStruct
● Java Champion
● 1⃣ 🐝 🏎
Gunnar Morling
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
#1BRC | @gunnarmorling
The Goals
Learn something
new
Have some fun
along the way
Inspire others to
do the same
Slide 9
Slide 9 text
#1BRC | @gunnarmorling
The Rules
● Java-only; Version of your choice
● No dependencies
● No caching
● 10K stations, -99.9°C - +99.9°C
● Copying allowed
#1BRC | @gunnarmorling
JEP 454
Foreign Function & Memory API
https://openjdk.org/jeps/454
Introduce an API by which Java programs can
interoperate with code and data outside of the Java
runtime. By efficiently invoking foreign functions
(i.e., code outside the JVM), and by safely accessing
foreign memory (i.e., memory not managed by the
JVM), the API enables Java programs to call native
libraries and process native data without the
brittleness and danger of JNI.
Slide 15
Slide 15 text
#1BRC | @gunnarmorling
Parallelization–Chunking the File
We have many cores,
let’s put them to use!
Slide 16
Slide 16 text
#1BRC | @gunnarmorling
Parallelization–Chunking the File
Slide 17
Slide 17 text
Parsing
jjmusgrove https://flic.kr/p/2mJbA8S (CC BY 2.0 DEED)
Slide 18
Slide 18 text
#1BRC | @gunnarmorling
Parsing – Byte by Byte
Slide 19
Slide 19 text
#1BRC | @gunnarmorling
Parsing – Byte by Byte
⌛ 20 sec.
Slide 20
Slide 20 text
#1BRC | @gunnarmorling
Parsing – SWAR
SIMD Within a Register
#1BRC | @gunnarmorling
Should You Do Any of This?
It
Depends
Slide 35
Slide 35 text
#1BRC | @gunnarmorling
The Hardest Earned Coffee Mug…
Slide 36
Slide 36 text
#1BRC | @gunnarmorling
Lessons Learned
Slide 37
Slide 37 text
#1BRC | @gunnarmorling
Lessons Learned
● Precise rules, covering corner cases
● Automate, automate, automate
● Build a community
● Use dedicated hardware
Slide 38
Slide 38 text
#1BRC | @gunnarmorling
Lessons Learned
Slide 39
Slide 39 text
#1BRC | @gunnarmorling
The 1BRC Community
● TCK
● Environment
● Evaluation Scripts
Slide 40
Slide 40 text
#1BRC | @gunnarmorling
1BRC Mythbusters
Slide 41
Slide 41 text
#1BRC | @gunnarmorling
What’s Next?
?
Slide 42
Slide 42 text
#1BRC | @gunnarmorling
● Repository
https://github.com/gunnarmorling/1brc/
● Show & Tell
https://github.com/gunnarmorling/1brc/
discussions/categories/show-and-tell
● The Billion Row Challenge–Step-by-step from 71s to 1.7s
https://questdb.io/blog/billion-row-challenge-step-by-step/
Learn More
Slide 43
Slide 43 text
#1BRC | @gunnarmorling
Resources
Relevant JEPs and more
● Vector API (Incubator): https://openjdk.org/jeps/469
● Foreign Function and Memory API:
https://openjdk.org/jeps/454
● CRaC: https://openjdk.org/projects/crac/