How to utilize specific cache levels in Golang?

Cache levels abstracted into a single concept, and we are taught way to make use of cache memory as if it was a single entity.

While abstracting multiple cache levels into a single one, makes it more simple, have you ever encountered scenarios, in your Golang code, where you had to take into account the specifics of a given cache layer ?

Please share your experiences.

Can you reword this, or elaborate? When you say “memory,” here, I think you mean CPU L1 vs. L2 vs. L3 cache. Is that what you mean? If yes, then I would say that, depending on what your program does, you probably want to try to write your program in such a way that it stays in the L1 cache. If your problem requires more than the amount of cache available in L1, then you continue to try your best to shrink the size of your data structures and code to fit into L1. If it “seeps” over into the L2 and L3 caches, that is unfortunate, but the only solution is to shrink your code and data to fit into those caches. If you are operating at such a level, I believe your best solution is to use assembly language and to thoroughly benchmark your code!

1 Like