Live data from Hacker News

Java is better than C++ for high speed trading systems

news.efinancialcareers.com

31–40 of 483 posts

Re: Java is better than C++ for high speed trading systems

#31
post #5

When you write Java in a C like syntax : "Chronicle's system is built in what Lawrey describes as "C-like Java" and it's this that he encourages people to code low latency systems in." I guess very limited number of constructors, and most of all the methods are static. And they still struggle to find programmers that can code that way.

This is also allegedly the programming style of C# used by StackOverflow to squizz performances.

Re: Java is better than C++ for high speed trading systems

#32

As an HFT programmer I like this article because it means less competition for me. I mean, you can write a very fast system in Java but by the time you accomplish that goal you’ll have spent as much or more time than if you had just used C++.

Do you think it’d be even faster if you used C?

Re: Java is better than C++ for high speed trading systems

#34
post #27
post #18

While I might not agree with the conclusion of the OP, the performance of a programming language should be always paired with its "average" programmers. A lot of people tend to straw-man a language they dislike and iron-man (?) a language they like. For an average programmer, I think it might be possible that Java produces a more performant/maintainable code than C++.

This is very true. I've seen colleagues port Python to C++ and wonder why it's slower. Of course Python is slow, but it will call into efficient C routines for a lot of things that aren't just available out of the box in C++. So what does the average programmer do? They implement their own, inefficient version of this in C++. Now you've saved the overhead of copying your data from the Python to the C-world and back,…

For that reason I generally motivate not using python to people on grounds of correctness rather than performance as per se. I can't be bothered to explain how compiler optimizations work so I usually just resort to "it's magic" when it comes to performance.

Going from a statically typed language to using python to do number crunching genuinely makes me want to vomit. I don't understand how people convince themselves that it's productive to write so many tests and (say) check types at runtime etc.

I actually love Python's syntax but the language design seems like it was thrown together over a weekend.

Re: Java is better than C++ for high speed trading systems

#35
post #24
post #15

Earlier quoted context omitted.

Avoiding allocations is the key part: "...we avoid all the garbage". I found the same is true when trying to write high performance Java UI code for Android. If you have to do something complex each frame, make sure to pre allocate or pool your objects. If the hot parts of the code are written in a C-like style, then the JIT and other optimizations can give you C-like performance. You'll still need to write C code if…

>"but writing in C-like Java can give you C performance while still letting you interact with Java libraries & APIs." Assuming those libraries do not do allocations of their own negating all the efforts.

I imagine that the other libraries would be used only on the non-critical parts of the application.

Re: Java is better than C++ for high speed trading systems

#36

I used to work on a high-speed messaging system built in Java, and garbage collection was a killer. No matter how much we tweaked the code and the GC parameters, and this eventually got escalated pretty high up in Sun itself, we'd get these occasional multi- minute pauses where the whole thing would just freeze up, buffers would fill and stuff would start dropping on the floor. This was over 10 years ago, so things m…

Another user commented here a while ago that they solved this problem by just throwing it on the largest instance by memory (1TB or so), disabled GC and restart it after market closes.

Re: Java is better than C++ for high speed trading systems

#37

As an HFT programmer I like this article because it means less competition for me. I mean, you can write a very fast system in Java but by the time you accomplish that goal you’ll have spent as much or more time than if you had just used C++.

Do you think it’d be even faster if you used C?

The one thing C++ can do better than C is inline a pipeline of operations using templates/type strictness which is handy for compiling all the (socket -> feed decoding -> book -> model) permutations without some macro trickery.

But otherwise they’re probably the same.

Re: Java is better than C++ for high speed trading systems

#38
Hearing them describe this "C-like Java", I'm surprised C# wasn't a better fit given that it has value-type "structs" that don't have to sit behind a reference on the heap. As far as I know, Java still doesn't have an equivalent feature.

Maybe the JVM's GC is just so much faster that it's worth it?

Re: Java is better than C++ for high speed trading systems

#39
post #5

When you write Java in a C like syntax : "Chronicle's system is built in what Lawrey describes as "C-like Java" and it's this that he encourages people to code low latency systems in." I guess very limited number of constructors, and most of all the methods are static. And they still struggle to find programmers that can code that way.

Use the stack and not the heap.

Pre-allocate arrays, avoid collections.

Use LUTs.

Avoid string processing, operate on bits and bytes as much as possible.

Same applies to telecoms-development that has to be fast and predictable.

Post reply on HN