News for hackers. Stuff that matters.
Re:C++ patterns for low-latency applications including high-... by nine_k on Monday July 08, 2024 @07:00PM (#40910691)
From my hearsay, you absolutely can, given two things: fewer pointer-chasing data structures, and, most crucially, fewer or no allocations. Pre-allocate arrays of things you need, run ring buffers on them if you have to use a varying number of things.

A fun but practical approach which I again heard (second-hand) to be used, is just drowning your code in physical RAM, and switch the GC completely off. Have enough RAM to run a trading day, then reboot. The cost is trivial, compared to spending engineering hours on different approaches.

Re:C++ patterns for low-latency applications including high-... by sneilan1 on Monday July 08, 2024 @08:10PM (#40911201)
So literally remove as much allocation as possible and then reboot each day. That makes a lot of sense to me!
Re:C++ patterns for low-latency applications including high-... by ramchip on Monday July 08, 2024 @08:26PM (#40911327)
I worked in trading and we did the first one, in C++. We'd load all the instruments (stocks etc.) on startup to preallocate the "universe", and use ring buffers as queues. Instruments don't change during trading hours so restarting daily to pick up the new data is enough.

I saw a Java team do the second one in an order router (a system that connects to various exchanges and routes+translates orders for each exchange's requirements), and they wrote an interesting retrospective doc where they basically said it wasn't worth it - it caused a lot of trouble without giving a significant edge in performance. YMMV! That was around 2012.

Re:C++ patterns for low-latency applications including high-... by bb88 on Monday July 08, 2024 @09:03PM (#40911562)
I honestly don't know why the real time trading devs don't make their own OS/programming language for this. It's not like they don't have the money.
Re:C++ patterns for low-latency applications including high-... by nine_k on Tuesday July 09, 2024 @02:40AM (#40913126)
Making your own OS or language is hard, if you care about both performance and correctness.

But HFT people do a lot of OS-level hacking, squeezing the last bits of performance from the kernel where the kernel is needed, and/or running parts of the kernel stack (like networking) in userspace, avoiding context switches. CPU core pinning, offloading of everything possible to the network cards, etc, goes without saying.

Re:C++ patterns for low-latency applications including high-... by pjmlp on Tuesday July 09, 2024 @07:29AM (#40914819)
That is basically what they do when deploying into FPGAs.
Re:C++ patterns for low-latency applications including high-... by bostik on Tuesday July 09, 2024 @01:43AM (#40912847)
> fewer or no allocations

Quite fitting in a thread about HFT that has already referenced game development as a parallel universe of similar techniques.

In the feature phone era, mobile phone games were written in Java (well, a subset: Java EE). Practically all games followed the same memory management strategy. They allocated the memory they needed during the early initialisation, and then never again during the actual runtime of the game. That was the only way to retain even a semblance of performance.