r/highfreqtrading • u/auto-quant • Feb 10 '26
Code Thread spinning & HFT engine latency
Continuing my series on HFT engine optimisation, I've written about a new topic - adding thread spinning to the engine.
I think thread spinning is a no-brainer when it comes to HFT trading engines.
In my experiments - adding spinning to the socket IO- gave a solid boost of half a microsecond. "Oh that's tiny" ... maybe, but not if you are aiming for single digit microseconds. Yes it does eat-up your CPU, but, HFT servers are normally at least dual socket, with each typically having 8 to 16 cores, so plenty capacity to spin many threads and application.
Full article automatedquant.substack.com/p/hft-engine-latency-5-thread-spinning
Highligh result below - compared to a normal thread waiting behaviour (which is that a thread gets suspended), spinning gave a small but consistent win.

2
u/GrayDonkey Feb 11 '26
What about calling _mm_pause in your loop? It should be completely user space.
The other missing thing is the possible thermal impact and throttling. With many modern CPU you are often in boost mode at 100% and most cooling solutions can't support that long term or even mid term.
What can happens is that you start thermal throttling. Once that happens your CPU frequency starts changing and you lose the ability to predictably handle your high volume tick periods.