Chapter 5. How Go Uses Memory Resource
In Chapter 4, we started looking under the hood of the modern computer. We discussed the efficiency aspects of using the CPU resource. Efficient execution of instructions in the CPU is important, but the sole purpose of performing those instructions is to modify the data. Unfortunately, the path of changing data is not always trivial. For example, in Chapter 4 we learned that in the von Neumann architecture (presented in Figure 4-1), we experience the CPU and memory wall problem when accessing data from the main memory (RAM).
The industry invented numerous technologies and optimization layers to overcome challenges like that, including memory safety and ensuring large memory capacities. As a result of those inventions, accessing eight bytes from RAM to the CPU register might be represented as a simple MOVQ <address XYZ> <destination register>
instruction. However, the actual process done by the CPU to get that information from the physical chip storing those bytes is very complex. We discussed mechanisms like the hierarchical cache system, but there is much more.
In some ways, those mechanisms are abstracted from programmers as much as possible. So, for example, when we define a variable in Go code, we don’t need to think about how much memory has to be reserved, where, and in how many L-caches it has to fit. This is great for development speed, but sometimes it might surprise us when we need to process a lot of data. In those cases, we need ...
Get Efficient Go now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.