Source code of the benchmarks? At least, the False Sharing and AddVectors trick don't work on my computer. (I only benchmarked the two. The "Data-Oriented Design" trick is a joke to me, so I stopped benchmarking more.) And I never heard of this following trick. Can anyone explain it? // Force 64-byte alignment for cache lines type AlignedBuffer struct { _ [0]byte // Magic trick for alignment data [1024]float64 } Mayb…
CPU cache-friendly data structures in Go
81–88 of 88 posts
Re: CPU cache-friendly data structures in Go
#82Earlier quoted context omitted.
The structure reads as LLM written. I don't mind this unless the content is utterly wrong. I was actually learning about cache-friendly data structures and I'm really interested in that cache-friendly Robin Hood hashing but now I worry it's a hallucination.
None of the tricks in this article get verified. Almost all of them are false.
Re: CPU cache-friendly data structures in Go
#83Earlier quoted context omitted.
huh TIL "On modern Intel architectures, spatial prefetcher is pulling pairs of 64-byte cache lines at a time, so we pessimistically assume that cache lines are 128 bytes long."
That was true in like, 2011. I'm not sure if it's true anymore.
Re: CPU cache-friendly data structures in Go
#84Earlier quoted context omitted.
Here's the one that showed a lot more speedup than the article: https://pastebin.com/v9tczpus Looks like the LLM invented somewhat different test for it than the article had. I tried again and have this with the same data structure as in the article: https://pastebin.com/SDdcchZG That gave similar results to the article. All the other tests still give little-to-no speedup on my machine.
Many thanks for providing the source. It also works on my machine. TIL.
Re: CPU cache-friendly data structures in Go
#85Earlier quoted context omitted.
Many thanks for providing the source. It also works on my machine. TIL.
I tried the others on my x86 machine and they all do something for me - not nearly as much as the article, but something.
For "Array of Structs vs Struct of Arrays", using slices as fields is a good idea. If the purpose is to make fields allocated on their respective memory block, just use pointers instead.
Re: CPU cache-friendly data structures in Go
#86Earlier quoted context omitted.
I tried the others on my x86 machine and they all do something for me - not nearly as much as the article, but something.
The "_ [0]byte" trick has no base in my knowledge. For the author's specified example, [1024]float64 will be always allocated on one whole page, aka, always 64-byte aligned. For "Array of Structs vs Struct of Arrays", using slices as fields is a good idea. If the purpose is to make fields allocated on their respective memory block, just use pointers instead.
You're right - I read the results I had wrong on that one. That one is slower, not faster, on both my M2 and on x86 machine.
Re: CPU cache-friendly data structures in Go
#87Earlier quoted context omitted.
The "_ [0]byte" trick has no base in my knowledge. For the author's specified example, [1024]float64 will be always allocated on one whole page, aka, always 64-byte aligned. For "Array of Structs vs Struct of Arrays", using slices as fields is a good idea. If the purpose is to make fields allocated on their respective memory block, just use pointers instead.
> The "_ [0]byte" trick has no base in my knowledge. For the author's specified example, [1024]float64 will be always allocated on one whole page, aka, always 64-byte aligned. You're right - I read the results I had wrong on that one. That one is slower, not faster, on both my M2 and on x86 machine.
> ... [1024]float64 will be always allocated on one whole page, aka, always 64-byte aligned.
if it is allocated on heap and at the start of allocated memory block.
> For "Array of Structs vs Struct of Arrays", using slices as fields is a good idea. If the purpose is to make fields allocated on their respective memory block, just use pointers instead.
I misunderstood it.
It is like row-based database vs. column-based database. Both ways have their respective advantages and disadvantages.