![]() The first is called temporal locality and it essentially means that if the processor is currently accessing a certain memory address, there is a high probability it will access the same memory address in the near future (think a counter in a loop). There are two principles that govern the behavior of the real world programs. In theory yes, but in practice accessing memory locations in random fashion is something real programs almost never do. So why does adding cache memory works? After all, the program can access any memory location at any time, therefore the data should never even be in the cache. Why does the memory cache make the system run faster? In this article we are concerned only about how to speed up your program by better using the data cache memory. The purpose of the first is to speed up access to instructions and the purpose of the second is to speed up access to data used by instructions. Normally cache memory is split into instruction cache memory and data cache memory. Otherwise it will have to wait for the main memory to provide the data and this involves a lot of wasted processor cycles. When the processor wants to access data in the main memory, it first check if the data is already present in the cache memory, and if so, it gets its data very fast. Clever hardware engineers have come up with a solution to offset the difference in speed: they add a small yet very fast memory called cache memory 1 that compensates for the difference in speed. In modern day systems memory is hundreds of times slower than the processor, so processor often has to wait for memory to deliver the data. Final Words on Data Cache OptimizationsĬomputer systems in general consist of processor and memory.Binary Search Algorithm with Software Prefetch.Tip: Avoid writing to memory if possible.Tip: Use your data while still in cache.Tip: Avoid heap allocation if stack could do.Tip: Avoid padding in your classes and structs.Tip: Access data in your matrices efficiently.Tip: Optimize access to array of classes or structs.Tip: Use array of values instead of array of pointers.Tip: Variables you access often together should be close to one-another in memory. ![]() Tip: When accessing data linearly, use vectors or arrays.Tips for making your program run faster.Why does the memory cache make the system run faster?.For those who are already familiar with memory cache in modern day multiprocessor systems, feel free to skip Data Cache chapter. We will explore some ideas on how to better leverage memory cache subsystems. This is the first post in the line of posts that will deal with low-level optimizations. Low level optimizations are all about how to best exploit the particularities of the underlying architecture to get better performance. It’s called: low-level optimizations.įirst a little bit about low-level optimizations. What now? Is there a way to squeeze out more performance out of our existing algorithm. This is the best way to go, but often not the possible way. Instead of O(n 2) complexity our new algorithm has a lower complexity of O(n log n) and we can carry on happily to our next challenge. If performance is in any way concern in your software project, feel free to contact us.ĭevelopers are confronted all the times with the need to speed up their programs and the most obvious way is to come up with a fancy new algorithm with a lower complexity. We at Johny’s Software Lab LLC are experts in performance.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |