False Sharing
ELI5 - The Vibe Check
False sharing is a performance bug where two threads aren't even touching the same variable, but because those variables happen to live on the same cache line, every write from one thread invalidates the other thread's cached copy anyway. The CPUs end up fighting over a shared cache line for data they never actually share, and your parallel code quietly runs like it's single-threaded.
Real Talk
False sharing occurs when independent variables used by different threads happen to reside on the same CPU cache line, causing the cache coherence protocol to invalidate and re-fetch the line on every write from either thread even though no data is logically shared. It manifests as unexplained slowdowns in multi-threaded code that disappear once the variables are padded onto separate cache lines.
When You'll Hear This
"The counters were logically independent but false sharing made them serialize anyway." / "We padded the struct to 64 bytes per field and the throughput doubled."
Related Terms
Cache Line
Your CPU never fetches just the one byte you asked for, it grabs a whole chunk around it, usually 64 bytes, called a cache line, on the theory that you'll...
Lock Contention
Lock contention is what happens when a mutex becomes the most popular door in the building, and instead of doing useful work, half your threads are just st...
Memory Ordering
Memory ordering is the unsettling fact that the order you wrote your instructions and the order the CPU and compiler actually carry them out are not the sa...
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...