Earlier quoted context omitted.
I don't know about java, but when using c++ you can use the OS to start the program, set up the hardware mappings and then move it to an isolated core where you talk to the hardware directly without ever issuing a system call. Compilers already offer flags to optimize for specific processor generations (and use the newly available instructions); you aren't going to be able to do better than that with a custom compile…
Oh, that's cool. However, you'd still be sharing at least 1 core (and all peripheral hardware and memory access in the system) with the OS. A core, other hardware and memory that you could otherwise access directly from your application without having to wait for the OS to finish its business? I'm not sure whether it's worth it to go through this trouble (writing for bare metal vs just using an off-the-shelve OS) in…
Java is better than C++ for high speed trading systems
181–190 of 483 posts
Re: Java is better than C++ for high speed trading systems
#182I’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…
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 features to do so.
Re: Java is better than C++ for high speed trading systems
#183So they want super efficient but safe code ... sounds like Rust.
Does anyone know of Rust in HTF teams? I think Haskell and OCaml may also be a good fit (and I know for a fact those are used in HFT teams).
Also, if memory serves, one of Lawrey's ex-colleagues has written his own version of Chronicle in D that's being used somewhere too.
Re: Java is better than C++ for high speed trading systems
#184Chronicle Software's OpenHFT stack has a few of their libraries: https://github.com/OpenHFT
Re: Java is better than C++ for high speed trading systems
#185C++ is a fantastic language but it somehow attracts people with big ego. The smartest people I know would always try to simplify things, but many C++ developers (especially in financial industry) have this preference for complexity I can't explain. And C++ is the worst language to get clever with.
I switched to C++ after years of doing web development in python, javascript and typescript, go and other high level languages associated with web dev. You're not wrong, the ego among C++ devs is astronomical. There's a huge amount of serious hate for python and this idea that being a C++ dev is superior. Get this we use Nix and C++ and the nix part of the code base is just as complex as the C++ code base. The nix st…
Re: Java is better than C++ for high speed trading systems
#186Creating liquidity has some value - though not as much as bankers tell themselves.
But HFT does not add liquidity. No one needs subsecond liquidity, but even more important, HFT traders vanish like a fart in a windstorm the moment liquidity is actually challenged.
Market makers are the ones who provide consistent liquidity, because they have to keep inventory of the stocks.
Now look at what HFT does - they flood the wires with hugely out-of-the-money bids and asks, all of which are in bad faith, because they know they won't even get hit or lifted.
So everyone else pays for this, and they get to shake absolutely everyone down for a few pennies, a trillion times a year.
---
It would be trivial to stop them without changing the markets in the least. Even just charging a dollar for every "bad faith" bid or offer made that expires without being within, say, 10% of the actual price, would put a big dent in them. Punitive taxes on trades where the trader doesn't keep the position for more than a few seconds would also be very effective.
Re: Java is better than C++ for high speed trading systems
#187We used Chronicle as a high performance messaging system. The secret sauce is just memory mapped files, single threaded processes, and using Java objects as flyweights that just write to the end of the file, or are read from the end of the file. No GC. When taking market data off the wire, or sending messages around a system, that is competitive with C++ and certainly has a fast time to market, and lower defect rate.
The other thing people are conflating is high frequency part: get the market data and... do a complex calculation as fast as possible, and place or pull an order. Placing or pulling orders can be further optimized too.
The fast complex calculation part is where Java isn't as competitive and you run into the GC unless you use object pooling, warming up the JVM and so on. We had a 50-50 system of Java for the bulk of the system, and C++ for the complex algorithms where we mark hot paths and check the assembly on godbolt (thank you Matt Godbolt).
Re: Java is better than C++ for high speed trading systems
#188Earlier quoted context omitted.
I switched to C++ after years of doing web development in python, javascript and typescript, go and other high level languages associated with web dev. You're not wrong, the ego among C++ devs is astronomical. There's a huge amount of serious hate for python and this idea that being a C++ dev is superior. Get this we use Nix and C++ and the nix part of the code base is just as complex as the C++ code base. The nix st…
I'm primarily a Java programmer, but I had a go at learning Python a little while ago. I couldn't stand it - it just seemed so sloppy and poorly-defined. I don't consider myself as being superior to Python devs or having an astronomical ego, but Python-hate? Yeah.
Re: Java is better than C++ for high speed trading systems
#189Earlier quoted context omitted.
Why not just write it in C? And pre-allocate all the data structures, make them global, put them into a queue, and constantly reuse them. No more need to instantiate objects.
Why not just write it in assembly while you’re at it? The answer to both questions is that many people prefer writing in higher-level languages with more safety guarantees.
Yes, of course $HIGH_LEVEL_LANG is preferable for many many use cases. In this context, we're discussing "high speed trading systems", for which native implementations are going to be the favorite.
Re: Java is better than C++ for high speed trading systems
#190Hearing 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?
Am also wondering (I have no experience on that matter) how .NET performs in terms of GC as I remember at some point they introduced a threaded GC that dropped the stop-the-world approach and perform garbage collection in dedicated threads. Anyone got some insights?
https://devblogs.microsoft.com/premier-developer/understandi...