3 ms·
> Cache is seen as an optimization for small data: if it fits in L2, it’s going to be processed faster Nobody worth their salt believes just this and nothing e
by kazinator 2y ago
> Cache is seen as an optimization for small data: if it fits in L2, it’s going to be processed faster
Nobody worth their salt believes just this and nothing else.
Yes, if the data fits entirely into a given cache, that's a nice case that's easy to reason about. No matter what access pattern is applied to the data, it doesn't matter because it's in the cache.
Hopefully everyone working with caches understands that they provide a potential speedup when not everything fits into the cache, and that this depends on the pattern of access (mainly, does it exhibit "locality"). Moreover, this case is extremely important.
The article gives an example of exactly that: improving the locality of access.
If you don't know this, you don't know one of the first facts about caching.
There is something else to know about: you can't tell by size alone whether a given data set will fit into a cache. The problem is that caches are not always fully associative. In a set associative cache, a given block of data cannot be stored in any cache line: it is assigned to a small set of possible cache lines. Then within a set, the cache lines are dynamically allocated and tagged. A given bunch of working which appears to be just smaller than the cache might be arranged in such a poor way in memory that it doesn't map to all of the cache's sets. And so, it actually does not fit into the cache.
- purplesyringa 2y agoThat's true, perhaps my wording is off. I believe that the devil in the details. Sure, knowing that better access patterns result in better performance is common. But the fact that the access pattern can be optimized when the problem is literally "access RAM at these random locations" is counterintuitive, IMO.
- ryao 2y agoWhen you have locality, prefetch can mask the latency of getting the next object, regardless of whether everything fits in cache.
- zahlman 2y ago>Nobody worth their salt believes just this and nothing else.... and that this depends on the pattern of access (mainly, does it exhibit "locality").... If you don't know this, you don't know one of the first facts about caching. Not necessarily specific to this issue, but I've found that surprisingly many people out there are not "worth their salt" in areas where you'd really expect them to be.
- HelloNurse 2y agoAssuming incompetence cannot be a general strategy, but there are many surprising ways to get jobs and pass exams.