1BRC SIMD, targeting both Java and C via Singeli #267
dzaima
started this conversation in
Show and tell
Replies: 3 comments 27 replies
-
Great stuff! Some test cases do not pass though
|
Beta Was this translation helpful? Give feedback.
2 replies
-
Could you try it on 1e9 records file?
|
Beta Was this translation helpful? Give feedback.
2 replies
-
I ran your code on a 2950X, running at 8 threads (default in your code). Same machine as here #138 , and you can download the file from my repo (13.8 GB, 1B lines)
|
Beta Was this translation helpful? Give feedback.
23 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
https://github.com/dzaima/1brc
Core SIMD logic written in Singeli, from which either Java
jdk.incubator.vector
usage or C AVX2 intrinsics are generated (repo comes with the code of both pregenerated so Singeli isn't required to run it).The core hot code is pretty much equivalent between C and Java, so this effectively shows the difference between the codegen of OpenJDK 21 and C (I'm testing on
clang-17
).As I only have 8GB RAM, I'm testing on a 100M-record input (i.e. 1.38GB) on my i3-4160 (Haswell, 3.6GHz), configured to run on 2 threads. C takes 0.56s, and Java - 3.3s (14.9s if ran 10 times in a loop in the same VM, simulating 1e9 records).
Some differences between the two:
C version uses a
vpgatherqq
to gather four 8-byte segments of the input for temperatures, but, while Java'sVector
does have gathers, they're only for aligned loads in same-type arrays, which don't work here (we need to load arbitrary-alignmentlong
s within abyte[]
), so it's emulated with four vector loads, stores to a temp buffer, and another load to construct the vector.Smaller things include using a
max(a-b,0)
instead of an unsigned saturating subtract, more manual digit multiplying where C uses a singlevpmuldq
, and a couple more similar things.But most of the perf difference should just be that OpenJDK generates less optimal machine code and does bounds checks.
Beta Was this translation helpful? Give feedback.
All reactions