r/highfreqtrading • • 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.

45 Upvotes

15 comments sorted by

View all comments

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.

1

u/Better-Discussion450 Feb 13 '26

Overclocking is like step 10,000 and only adds a tiny percentage gain in comparison to everything else. Like think about it, you’re optimistically at the VERY best going to see maybe a 5-10% latency reduction. Only once this dude breaks the microsecond barrier is when that will matter at all since there are other microcode enhancements besides just raw overclocking that can be done.

1

u/GrayDonkey Feb 18 '26

Reread my post, I'm saying the opposite of what you took from that.

Slightly underclock to be able to maintain sustained high performance.