How does the Go race detector work conceptually, and what are the performance trade-offs of using it during testing?
Last updated
With
-race, the compiler instruments every memory access and sync event. A happens-before (vector-clock) model flags two concurrent unordered accesses where at least one is a write.It only catches races that actually occur during the run, so it needs representative concurrent workloads. Reported races are real (no false positives).
It costs roughly 5-10x CPU and memory, so run it in tests and CI, not production.