Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

#1BRC | @gunnarmorling Today’s Mission Learn About…

Slide 6

Slide 6 text

#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

Slide 10

Slide 10 text

#1BRC | @gunnarmorling Evaluation Environment ● 32 core AMD EPYC™ 7502P (Zen2), 8 Cores used ● 128 GB RAM ● File on RAM disk ● Five runs, slowest and fastest discarded Image © Joe Haupt https://flic.kr/p/2mG3vWA (CC BY-SA 2.0)

Slide 11

Slide 11 text

#1BRC | @gunnarmorling Baseline ⌛ 04:49.679

Slide 12

Slide 12 text

Parallelization Ozzy Delaney https://flic.kr/p/pMsvzE (CC BY-SA 2.0 DEED)

Slide 13

Slide 13 text

#1BRC | @gunnarmorling Parallelization ⌛ 71 sec.

Slide 14

Slide 14 text

#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

Slide 21

Slide 21 text

#1BRC | @gunnarmorling Parsing Branchless Programming https://en.wikipedia.org/wiki/Branch_predictor

Slide 22

Slide 22 text

#1BRC | @gunnarmorling Parsing – SWAR SIMD Within a Register https://richardstartin.github.io/posts/finding-bytes

Slide 23

Slide 23 text

#1BRC | @gunnarmorling Parsing – SIMD Single Instruction, Multiple Data https://speakerdeck.com/gunnarmorling/to-the-moon-and-beyond-with-java-17-apis

Slide 24

Slide 24 text

Bookkeeping R. D. Barry https://flic.kr/p/P5RWWR (CC BY-SA 2.0 DEED)

Slide 25

Slide 25 text

#1BRC | @gunnarmorling Custom Maps – Linear Probing

Slide 26

Slide 26 text

#1BRC | @gunnarmorling Custom Maps – Hash Collisions!

Slide 27

Slide 27 text

#1BRC | @gunnarmorling Further Tricks & Techniques ● GraalVM as JIT Compiler ● GraalVM native binary ● The “spawn trick” ● Unsafe ● EpsilonGC ● Super-scalar execution

Slide 28

Slide 28 text

#1BRC | @gunnarmorling Parsing Perfect Hashing ● Can’t use perfect hashing for keys… but for values! ● Only 1,999 distinct values: -99.9, -99.8, ..., 0.0, ..., 99.8, 99.9

Slide 29

Slide 29 text

The Results Clint Budd https://flic.kr/p/2m6F7hw (CC BY 2.0 DEED)

Slide 30

Slide 30 text

#1BRC | @gunnarmorling Results

Slide 31

Slide 31 text

#1BRC | @gunnarmorling Results – 32 Cores / 64 Threads

Slide 32

Slide 32 text

#1BRC | @gunnarmorling Results – 10K Key Set

Slide 33

Slide 33 text

#1BRC | @gunnarmorling It’s a Long Journey

Slide 34

Slide 34 text

#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/

Slide 44

Slide 44 text

#1BRC | @gunnarmorling Resources Hacker’s Delight

Slide 45

Slide 45 text

#1BRC | @gunnarmorling [email protected] @gunnarmorling 📧 Thank You! Q & A

Slide 46

Slide 46 text

No content