rgoussu@goussu: ~/library/java/exercises
~/library/java/exercises cat one-billion-row-challenge.md

One Billion Row Challenge

# Gunnar Morling's 1BRC — aggregate a billion temperature readings as fast as the JVM allows, profiling from naive baseline to memory-mapped byte crunching.

Exercisesaved 2026-08-08source #exercise#java#jvm#performance#profiling#1brc

Goal

Compute min/mean/max temperature per station over a one-billion-row text file, in Java, as fast as possible. The skill proved is JVM performance engineering as a measured discipline: profile, hypothesize, change one thing, measure again — from a 4-minute baseline down toward the leaderboard's sub-2-second range.

Subject: full brief & instructions

Practices

  • Deep dive Java — JIT behavior, GC pressure, JFR/ async-profiler, virtual vs. platform threads: the internals, exercised under load.
  • Performance engineering — measure-first methodology, mechanical sympathy, and the memory hierarchy deciding everything.
  • Concurrency and Parallelism — data parallelism with a merge step, done by hand.

Milestones

  1. Baseline. Generate the 1B-row file with the repo's tooling; write the obvious solution (BufferedReader, String.split, HashMap). Record wall time — this number is your denominator.
  2. Profile & fix the obvious. Run JFR or async-profiler; kill the top offenders — split and substring allocation, autoboxing of doubles, String keys. Custom line parsing, primitive accumulators. Measure.
  3. Go parallel. Split the file into chunks along newline boundaries, process per thread, merge the per-thread maps. Compare platform threads vs. virtual threads and understand why this workload doesn't care.
  4. Memory-map it. MappedByteBuffer (or the FFM API), parse bytes directly — no String until output, temperatures as scaled integers. Measure the drop.
  5. Steal like an engineer. Read the top leaderboard entries — SWAR temperature parsing, branchless dispatch, custom open-addressing hash tables — port one technique at a time, and keep only what your measurements justify.

Stretch goals

  • GraalVM native-image build; compare startup and peak against JIT.
  • Port your fastest version to Go and Rust — Deep dive Go, Deep dive Rust — and write up who wins where and why.

Related