r/cpp • u/User_Deprecated • Mar 24 '26
Rewriting a FIX engine in C++23: what got simpler (and what didn't)
I spent a few months building a FIX protocol engine from scratch in C++23. Not because the world needed another one, but because I wanted to see how far modern C++ can take a FIX engine compared to QuickFIX.
QuickFIX was written by people who knew what they were doing. It also reflects the constraints and tooling available at the time. But it's very much C++98/03 era code: custom object pools, hand-rolled lock-free queues, manual cache line alignment. A lot of infrastructure that today overlaps with standard or near-standard tools.
The surprising part was how much of that code simplifies with C++23.
The original object pool was ~1000 lines of allocation logic. In the new version that's std::pmr::monotonic_buffer_resource with per-message reset.
Tag lookup went from a large switch with 50+ cases to a consteval table computed at compile time, O(1) at runtime with no branches.
Delimiter scanning went through three SIMD approaches (intrinsics, Highway, xsimd). Ended up going with xsimd. Maintaining separate AVX2/AVX-512 paths wasn't worth the extra complexity for ~5% throughput.
Current result (microbenchmarked with RDTSC, single-core, warmed cache, using synthetic FIX messages): ExecutionReport parse ~246 ns vs ~730 ns for QuickFIX on the same input, over 100K iterations.
No heap allocations on the hot path.
Not production-ready yet, but the parser and session layer are stable enough to compare.
A couple of things still being figured out:
- Header-only at ~5K LOC. Compiles fine locally, but not sure where CI starts to struggle
- Only covering 9 FIX message types so far. Interested in any edge cases people have run into
13
u/FlailingDuck Mar 24 '26
FYI, you can do object pooling with the standard std::vector with custom allocator. pmr allows you to switch allocators at runtime or reuse allocators via dependency injection across multiple objects i.e. can be useful for using a tracking allocator during testing but no recompilation needed for release builds.
Nothing wrong with choosing pmr though, just letting people know, the std doesn't require you to use pmr when you just want a memory pool.
4
u/Nicksaurus Mar 24 '26
One criticism: throughout the readme it's not very clear where you're talking about parsing and where you're talking about generating messages, particularly for the benchmarks. e.g. what does 'field access' or 'processing a NewOrderSingle message' mean? Reading or writing?
After reading through it carefully, I believe all the benchmarks are for parsing messages, which is a bit odd when you've clearly put a lot of work into optimising message encoding with constant field offsets
Anyway, that's a relatively minor complaint. This looks like a really nice project and anything that means people don't have to use quickfix any more is a good thing in my view
Also, presumably this doesn't do any of the automatic session management logic that quickfix does? It's basically just for reading/writing messages, and you have to send the individual logon/heartbeat/etc. messages yourself?
2
u/bbmario Mar 25 '26
I see that you went with Quill. Have you guys experimented with spdlog at all?
1
u/Arghnews Mar 24 '26
/u/User_Deprecated thanks for sharing. Is there a way that anyone can try this on some live or old data? Except for the tests and benchmarks included?
Also considering how pedantic this whole thing is about performance, I'm surprised in the performance_diary you mention that std::string always allocates. That isn't necessarily always true due to short string optimisation. The limits of which are I think like 15 and 22 bytes for libstdc++ and libc++. For data items like
orderIDandsymbollike you have there, you'd presume in many cases they'd fit. I realise especially for HFT that variance is the enemy, so that it's still poor to maybe allocate.1
u/SilkHart Mar 27 '26
FIX engines are such a beast to get right especially with C++23. That concern about the CI struggling is real though once those template heavy headers start stacking up. I have seen teams in similar HFT setups use Incredibuild to distribute the load across the grid so the CI does not just choke and die. It is usually the move when you want to keep those execution report parse times fast without sacrificing the iteration speed on the dev side.
1
u/Maleficent_Hair_7971 Apr 13 '26
Just some feedback. Usually the biggest burden in real world use cases is that every venue has some form of custom fix formatting. Thus you need all of your messages to be automatically generated code from xml files. Writing this by hand is not feasible when you support 30+ flavors of FIX. you should consider how to ensure you can supply fix xml schema and generate all of the messages (and perhaps even more just from the schema). The rest is fairly easy.
11
u/[deleted] Mar 24 '26
[removed] — view removed comment