Memory Hierarchy: Performance OptimizationThis page describes the memory hierarchy. This hierarchy determines the efficiency of data access.
Optimization involves the memory hierarchy. We see an example memory hierarchy in a fairly modern computer. This guides optimization of computer programs. It also influences how compilers, operating systems and databases work.Optimization
Virtual Memory: Disk
> 2GB (Typical size)
3-15 ms (Access time)
shows the critical performance aspects of a somewhat recent memory hierarchy on a personal computer. You can see that reading a file from the disk requires about 3-15 milliseconds.Compilers: stanford.edu
So: Reading data from memory requires 100-150 nanoseconds. And reading data from the processor caches requires 1-60 nanoseconds.
How much faster
is physical memory than the disk? Here we use the table shown above to compute how much faster you can load a small data object from memory instead of the disk. Parsing time is not included.
Note: Please recall that one millisecond is equal to one million nanoseconds. One nanosecond is quite small.
And: Let us say that the computer is busy and the disk requires 15 milliseconds, and the memory requires 150 nanoseconds.
15 ms * 1000000 = 15000000 ns
Memory is 100,000x (one-hundred thousand) times faster.
There is more complexity to computers than this memory hierarchy. All modern operating systems use a file cache, which puts disk files into memory, essentially making accesses one-hundred thousand times faster.
However: This is not configurable in many cases and it can be better to use custom file caches that will not be expired.
We explored the memory hierarchy using a table from the book Compilers: Principles, Techniques and Tools. The memory hierarchy shows us that disk accesses are far more expensive than in-memory reads with similar complexity.
Often: Avoiding accessing virtual memory (disk) is an important optimization to make.
© 2007-2019 Sam Allen. Every person is special and unique. Send bug reports to firstname.lastname@example.org.