CPU cache-friendly data structures in Go
skoredin.pro
CPU cache-friendly data structures in Go
1–10 of 88 posts
Re: CPU cache-friendly data structures in Go
#2[deleted]
Re: CPU cache-friendly data structures in Go
#3> False Sharing : "Pad for concurrent access: Separate goroutine data by cache lines"
This is worth adding in Go race detector's mechanism to warn developer
Re: CPU cache-friendly data structures in Go
#4I wonder how many nanoseconds it'll take for the next maintainer to obliterate the savings?
Re: CPU cache-friendly data structures in Go
#5Looks nice. Some explanation for those of us not familiar with Go would've been more educational. Could be future posts, I suppose.
Re: CPU cache-friendly data structures in Go
#6Most of this should be handled by the compiler already. But it is only 2025, I guess we're just not ready for it.
Re: CPU cache-friendly data structures in Go
#7Overall great article, applicable to other languages too.
I'm curious about the Goroutine pinning though:
// Pin goroutine to specific CPU
func PinToCPU(cpuID int) {
runtime.LockOSThread()
// ...
tid := unix.Gettid()
unix.SchedSetaffinity(tid, &cpuSet)
}
The way I read this snippet is it pins the go runtime thread that happens to run this goroutine to a cpu, not the goroutine itself. Afaik a goroutine can move from one thread to another, decided by the go scheduler. This obviously has some merits, however without pinning the actual goroutine...Re: CPU cache-friendly data structures in Go
#8> False sharing occurs when multiple cores update different variables in the same cache line.
I got hit by this. In a trading algorithm backtest, I shared a struct pointer between threads that changed different members of the same struct.
Once I split this struct in 2, one per core, I got almost 10x speedup.
Re: CPU cache-friendly data structures in Go
#9I wonder how many nanoseconds it'll take for the next maintainer to obliterate the savings?
That's just one prompt away!
Re: CPU cache-friendly data structures in Go
#10> False sharing occurs when multiple cores update different variables in the same cache line. I got hit by this. In a trading algorithm backtest, I shared a struct pointer between threads that changed different members of the same struct. Once I split this struct in 2, one per core, I got almost 10x speedup.
Interesting! Did you find out a way to bench this with the built in benchmarking suite?