Live data from Hacker News

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

news.efinancialcareers.com

431–440 of 483 posts

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

#431

Let me put my perspective on this. As it happens, I have developed one algorithmic, low latency trading system in Common Lisp / ANSI C, and then was asked to rewrite it in Java which I did. It actually traded on Warsaw Stock Exchange and was certified by WSE and was connected directly to it (no intervening software). Yes, it is possible to do really low latency in Java. My experience is my optimized Java code is abou…

One interesting approach I heard about for doing garbage collection in finance is to get computers with a shitload of RAM and just turn off GC. At the end of the trading day you can reclaim memory by killing the process. Not sure how common that strategy is.

That is exactly what I did. It was much less elegant and performant, though, than my initial solution with Common Lisp and C which basically allocated buffers in memory and mapped them with huge pages so that memory access don't ever require switch to kernel for mapping.

We also had custom Intel CPUs that are auctioned individually. And cutthrough switches that stream the IP packet immediately when they receive the IP header, before they receive the payload. I have calculated that if the message from exchange was a beam of light it would be delayed by less than a meter.

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

#432

Earlier quoted context omitted.

> I remember just refactoring all of foreach-loops/iterators into for-loops and got insane speedups. Wow! Can you please provide a simple example when/where it happens? > It's possible to write efficient Java but you have to not use some of the language features to do so. Please tell us more.

Let's say you write an Iterable class so that you can use foreach on your data structure. It's quite possible iteration won't be completely inlined and the overhead of calling hasNext & next can become non-significant. An even worse case that made massive speedups is just inlining everything. I believe modern IDEs can automatically inline all invocations of a function. You'd be surprised how much performance you can…

But you still have to make the next and hasNext calls in a for loop. What guarantees that they would be inline in a for loop?

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

#433
post #384

Earlier quoted context omitted.

So Java is nearly as low-latency as C if you're willing to write your Java as if it were C?

No. Java is not low-latency by any stretch. Java advocates would like to think it is, until a Bank, like BoA spends $8 million on Java in 2014, just to have it fail compliance testing. Entire project was scrapped.

I think this may not due to programming language, but beyond that.

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

#436

I’ve seen this sentiment before and worked on both a “low latency Java” team and low latency C++ teams. I have some sympathy for the idea that the JVM is better since it means you won’t spend all your time chasing crash reports. The thing is, like another comment hinted at, is that this issue is generally more reflective of the environment you build in than the technology choice. Here’s a good talk on the reasons for…

From my experience, JVM can't do much when there's a deep stack. I remember just refactoring all of foreach-loops/iterators into for-loops and got insane speedups. Functions with inefficient iterations would get optimized if called directly but deep in the call stack and nothing happens. These kinds of things are impossible with C++. It's possible to write efficient Java but you have to not use some of the language f…

[deleted]

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

#437

Earlier quoted context omitted.

I'm curious, what role did Common Lisp play in the original version of your trading system?

Common Lisp was doing all the "high level" stuff. No CL code was on the actual critical path but it still was responsible for some critical things that would be difficult otherwise. For example, I had piece of Common Lisp code optimize and compile decision trees to machine code. These were used, for example, to check whether the trade is allowed to go to market. This had to be very optimized as it was running in para…

> did not talk to operating system (Linux) after it started (no syscalls at all) and used full kernel bypass to talk to NIC

That's really interesting... How does it work? How can a user space program talk to the NIC directly without using system calls? Shared memory?

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

#438

Let me put my perspective on this. As it happens, I have developed one algorithmic, low latency trading system in Common Lisp / ANSI C, and then was asked to rewrite it in Java which I did. It actually traded on Warsaw Stock Exchange and was certified by WSE and was connected directly to it (no intervening software). Yes, it is possible to do really low latency in Java. My experience is my optimized Java code is abou…

One interesting approach I heard about for doing garbage collection in finance is to get computers with a shitload of RAM and just turn off GC. At the end of the trading day you can reclaim memory by killing the process. Not sure how common that strategy is.

If that's your memory management strategy, then what do you actually gain by using Java?

May as well just use C and never free your memory. Lots of memory management issues go away if you never free memory.

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

#439
post #399

'The problem with C++ is its fallibility, says Lawrey: "If you're not a really good C++ developer, you can shoot yourself in the foot and bring an entire project down."' 'The only problem with low latency Java is that most experience(sic) Java programmers struggle with the new paradigm.' So...badly written C++ isn't reliable, and well written, idiomatic Java isn't performant...so the solution proposed is, rather than…

Or use Rust as it fits this particular use case where you need a language that’s low-level and safe.

I mean, sure, but kind of left field there, no? I'm solely quoting the article and pointing out that the statements made, taken together, make the conclusion the guy came to seem very...strange.

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

#440
post #416

Earlier quoted context omitted.

No. Java is not low-latency by any stretch. Java advocates would like to think it is, until a Bank, like BoA spends $8 million on Java in 2014, just to have it fail compliance testing. Entire project was scrapped.

US Navy thinks otherwise, https://www.ptc.com/en/blogs/plm/ptc-perc-virtual-machine-te...

250ms is not real-time, nor high frequency.
Post reply on HN