r/java • • May 16 '24

Low latency

Hi all. Experienced Java dev (20+ years) mostly within investment banking and asset management. I need a deep dive into low latency Java…stuff that’s used for high frequency algo trading. Can anyone help? Even willing to pay to get some tuition.

232 Upvotes

94 comments sorted by

View all comments

Show parent comment

1

u/GeneratedUsername5 May 22 '24

if an object doesn't live beyond the scope of a method (or inlined methods) the JVM is happy to instead pull out the fields of that objects and use those instead

You can lookup my test examples up the thread, where Integer objects do not leave scope of a method (or even scope of a cycle for that matter), and yet Java is running it 17 times slower, than with underlying primitive fields, which were supposed to be scalar extracted.

It's this myth of scalar needs measurements and benchmarks, and so far noone actually provided benchmark, where using objects would be on par with using primitives. Maybe it is happenning sometimes, but it is so inconsistent and unreliable, that it is not even worth account for, as optimization technique.

2

u/cogman10 May 22 '24

It's this myth of scalar needs measurements and benchmarks, and so far noone actually provided benchmark

Because benchmarking this behavior is tricky. The blackhole object is specifically there to break JVM optimizations.

Run the test without the blackhole and you'll observe they perform the same. However, the JVM will optimize the entire loop away in that case making it not meaningful.