Context Switch
ELI5 - The Vibe Check
A context switch is the CPU pausing whatever thread it's running, carefully saving all its progress like a bookmark, and loading up a completely different thread's bookmark to run instead. It's how one CPU core convincingly juggles far more threads than it has room for, but each switch costs real time doing nothing useful, just shuffling bookmarks, which is why having way more threads than cores can actually make things slower.
Real Talk
A context switch is the process of storing the state of a currently running thread or process and restoring the state of another, allowing a single CPU core to time-share between multiple execution contexts. Context switches have real overhead, saving and restoring registers and often invalidating CPU caches and the TLB, which is why excessive thread counts or lock contention that triggers frequent switching can hurt throughput even on an otherwise idle machine.
When You'll Hear This
"We had ten thousand threads fighting over four cores, the context switch overhead alone was killing us." / "Async runtimes exist partly to avoid the cost of a context switch per blocked operation."
Related Terms
Green Thread
Green threads are fake threads managed by your programming language instead of the operating system.
NUMA (Non-Uniform Memory Access)
On a big multi-socket server, not all memory is created equal, memory attached to your CPU socket is fast to reach, and memory attached to the other socket...
Page Fault
A page fault happens when your program reaches for a piece of memory that isn't actually sitting in physical RAM yet, maybe it was swapped out, maybe it's...
Syscall
A syscall is your program raising its hand and asking the operating system kernel to do something it isn't allowed to do itself, like reading a file, openi...