C multithreading experiment: padding counters to 64 bytes yields 3-4x speedup via false sharing fix
cneuralnetwork · x · 2026-10-23
The author ran a C multithreading experiment: two threads each incrementing separate counters 20 million times ran 3-4x faster after simply adding padding between the counters.
The cause is false sharing — CPUs maintain cache coherence at the cache-line level (typically 64 bytes), not per variable. Even though the threads touched different counters, they kept invalidating each other's cache line; separating them in memory removed most of the overhead. Five benchmark rounds show consistent 2.7x-4.6x speedups with identical final counts.
More from Infra
- Google Cloud launches Agent Compute Engine, a new VM type built for AI agents — testingcatalog · 2026-10-23
- LM Studio ships Read Aloud, powered by tiny local TTS model Phonon from Gradium — mattturck · 2026-10-23
- Lam Research system revenue up 35% QoQ as AI pushes 2027 WFE past $200B — BenBajarin · 2026-10-23
- Hugging Face Hub launches OpenUSD support with 2,500+ NVIDIA SimReady assets — mishig25 · 2026-10-23
- One lying fsync() on a single node can make a Raft cluster lose data — tianyin_xu · 2026-10-23
- Hacked DFlash drafter runs on stock llama.cpp, +61% code speedup for Ling-3.0-tiny — Barni275 · 2026-10-23