What is actually inside the box
Almost every real performance question an engineer faces comes down to which physical part of the computer the data is sitting in. Why an app is slow, why unsaved work disappeared, why a server falls over when it runs out of memory: all three are answered by naming the part. So this course starts with the parts.
Every computer you have ever used, from a laptop to a phone to a server in a data center, is built from the same three:
- The CPU, the central processing unit, executes instructions, tiny steps such as adding two numbers or copying a value, billions of times per second. It is the only part that actually computes anything.
- RAM, random access memory, holds the data and programs the CPU is working on right now, because the CPU can only keep up its speed on data it can reach in nanoseconds. RAM is fast and loses everything the instant power is cut. If a picture helps, it is the desk you spread your work out on.
- The disk, an SSD or a hard drive, keeps files permanently even with the power off, because it stores data in a physical form that needs no electricity to persist. Reading it is much slower than RAM. It is the filing cabinet next to that desk.
Everything your code does maps onto these three parts, and the rest of this course is mostly about how the operating system shares them out.
Why three parts and not one
Speed and permanence pull in opposite directions. Fast memory is expensive and loses data without power, while cheap permanent storage is slow.
So computers use a hierarchy: a tiny amount of very fast memory close to the CPU, a medium amount of RAM, and a huge slow disk.
Rough numbers worth keeping in your head:
| Part | Typical size | Read time |
|---|---|---|
| CPU cache | megabytes | about 1 nanosecond |
| RAM | gigabytes | about 100 nanoseconds |
| SSD | terabytes | about 100,000 nanoseconds |
A nanosecond is a billionth of a second. The exact numbers vary by machine, but the ratios are what matter, and the disk is roughly a thousand times slower than RAM.
That ratio is the reason so much of systems engineering is about avoiding the disk. Caches, buffers, and in-memory databases all exist to answer a question from RAM instead of from storage.
Turning the table into a ratio
A typical RAM read against a typical SSD read, using integer division so the answer comes out whole.
ram_speed_ns = 100 ssd_speed_ns = 100_000 print("RAM read:", ram_speed_ns, "nanoseconds") print("SSD read:", ssd_speed_ns, "nanoseconds") print("The SSD is", ssd_speed_ns // ram_speed_ns, "times slower")
Output
RAM read: 100 nanoseconds SSD read: 100000 nanoseconds The SSD is 1000 times slower
The underscores in 100_000 are only for readability, and Python ignores them entirely.
A factor of 1000 is easier to feel in human units. If a RAM read took one second, the matching SSD read would take about seventeen minutes, which is why a program that touches the disk in a tight loop feels frozen.
All three ratios side by side
The same integer-division shape applied across the whole hierarchy.
cache_ns = 1 ram_ns = 100 ssd_ns = 100_000 print("RAM is", ram_ns // cache_ns, "times slower than cache") print("SSD is", ssd_ns // ram_ns, "times slower than RAM") print("SSD is", ssd_ns // cache_ns, "times slower than cache")
Output
RAM is 100 times slower than cache SSD is 1000 times slower than RAM SSD is 100000 times slower than cache
Integer division with // gives a whole number, which is what makes these ratios readable rather than printing a long decimal.
The last line is the one to remember. Between the fastest and slowest storage in a single machine there are five orders of magnitude, which is why "where does this data live" is usually a bigger performance question than "how many instructions does this run".
Why unsaved work vanishes and saved files do not
When the power cuts out mid-edit, the unsaved changes are gone because they lived in RAM, which loses everything without power. The file saved an hour ago is fine because it sits on disk.
RAM is fast working memory, but it is volatile, so no power means no data. The disk is persistent storage.
| Where the change was | On power loss |
|---|---|
| in RAM, unsaved | lost |
| on disk, saved | intact |
Saving a file literally means copying it from RAM to disk, which is the whole reason editors nag about it and why autosave is implemented as a periodic copy rather than as a smarter kind of memory.
The volatile part
RAM is the part that loses its contents the instant power is cut.
It is volatile memory, fast to read and write, but it needs constant power to hold anything. Each bit is stored as a charge that has to be actively refreshed, and refreshing stops when the power does.
The disk is the opposite: slow, and persistent without any power at all.
The distinction sets up almost everything later in this course. A process lives in RAM and dies with the machine, while a file lives on disk and outlives every process that touched it.