Billion row challenge: parsing temperatures fast(ish)
February 20, 2026 [Programming, Rust, Tech, Videos]I watched Jon Gjengset taking on the one billion row challenge
and got interested in one small corner of it: parsing temperatures, and in
particular parsing temperatures in a "branchless" style - with no if
statements - to help the CPU run the code as fast as possible. In the end, the
results were surprising.
After the stream I added a version of Jon's parse_temperature to the
comparison. His version assumes we already know where the semicolon is, so I had
to add code to find it, and I didn't use the SIMD code he used to do that
because it requires unstable Rust. With those caveats, my version was 4x
faster(!). However, I'm pretty sure we're going to need to find that semicolon
ourselves if we take on the full challenge, so this is not a fair comparison.
Also after the stream I realised I'm pretty sure there is a simple improvement I can make to branchy to make it even faster...
Follow me on mastodon: @andybalaam@mastodon.social
Tiger12506 2026-07-19
The assembly for branchy is pretty wild.
LBB5_3 label code at the end is always run. It checks for hyphen, sets up -1 (65536), and moves it into reg only if the compare says there was hyphen (cmovnew), and applies the negative sign (imul) before return (ret)
So the jumps above it are skipping over the blocks before the label.
or (x + x) * 4 + x is a cheap way of multiplying by 10 (leveraging pointer offset calculation hardware of lea instr)
There will always be a digit after the decimal and before the decimal, and the compiler knows this, so by the time it sets up first digit (mov edx, byte ptr [rdi + rsi - 4]), it has already computed answer for last digit and second digit, and stored that result in eax.
That frees up ecx (cx) to become the sign variable, which gets initialized to -1 (mov cx, -1)
jae = jump if above or equal, which is basically jge, just for unsigned (0xFF > 0x01)
And lastly of interest...
Interesting that the compiler moved the '0' - '9' check into the 0 - 9 domain to be able to turn the two-sided range check into a one-sided above 9 check.
Lots of instruction re-ordering by the compiler.