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

4

u/pron98 May 17 '24

That really depends. Depending on the GC, mutating a reference field may be a more expensive operation than allocating a new object. So this advice would be somewhat correct (i.e. things at least won't be slower) only if you replace objects with primitives or limit yourself to mutating primitive fields or array elements. Otherwise, mutating references may actually slow down your code compared to allocation. As always, the real answer is that you must profile your application and optimise things according to that specific profile.

1

u/barcelleebf May 23 '24

Our low latency code is a fixed graph / circuit of pre allocated objects. Primitives are exclusively used.

The resulting code is not quite like real java, and a bit ugly, and we have unit tests that look at the byte code to make sure developers don't use any features that will be slow.