Pushing Java to the Limits: Processing a Billion Rows in under 2 Seconds by ROY VAN RIJN

8,570
0
Published 2024-05-15
For updates and more, join our community 👉 www.linkedin.com/company/devoxx-united-kingdom

Last January a challenge was posted online by Gunnar Morling:
How fast can you parse a file with one billion rows of weather data using Java?
Little did I know this deceivingly simple question would lead me down a path that taught me all about: parallelism, memory mapped files, SWAR techniques (SIMD as a register), bit twiddling, branchless code, mechanical sympathy, Graal native compilation and finally... I even turned to the dark side: using sun.misc.Unsafe.
Join me in this deep dive where I'll explain all the code changes and tricks that took me from the reference implementation which processes the billion records in less than 4 minutes, to processing everything in under two seconds.
Who knew Java could be this fast

All Comments (10)
  • @KangoV
    We should soon have the "inline" keyword. A huge effort is being performed for this in the JVM so that, for example, an array of inline objects will use contiguous memory. When iterating through, you get huge speedups as you avoid all those cache misses (30x have been seen).
  • @Anbu_Sampath
    Crazy engineering effort went in this challenge.
  • @TechTalksWeekly
    Roy's talk has been featured in the last issue of Tech Talks Weekly newsletter 🎉 Congrats!
  • @northdankota
    I think branchless programing fast too because of the CPU cache memroy loads with bulk (from the ram to l1 l2 l3 cache), like load the hole 64 bit block the requsted data around, therefore not only requested data load, the cpu loads after the data and there is a next section of the data, this adds more optimization
  • @Dragiux
    As far as I remember constant maths can be performed at compile time (such as static final int foo = 1+1 would be written to the file as static final int foo = 2). Could you trick the compiler to do all of this heavy lifting and only produce the binary that contained final results?
  • @lugburzhr8081
    So to process 1 billion rows in Java in 2 seconds you need to use C\C++. Great job anyway!
  • @bilgehan
    It was fun and interesting until i saw unsafe. after that it felt meaningless, empty satisfaction imho