Lock Contention Profiling
A program can be fully correct yet slow because threads spend their time waiting for locks instead of working. Lock contention profiling measures exactly where that waiting happens so you can fix the worst offenders.
A contention profiler records, for each lock, how often a thread had to wait to acquire it and how long it waited in total. High wait time on a lock means many threads compete for it, serializing work that could otherwise run in parallel. The lock becomes a bottleneck, and adding more cores stops helping.
- Wait time, not hold time The signal is how long others waited, which reveals contention rather than just usage.
- Hot locks A single heavily contended lock can cap the whole program throughput.
- Acquisition stacks Good profilers show which call sites fight over the lock, pointing you at the code to fix.
Typical fixes follow from the data. Shrink the critical section so the lock is held briefly, split one coarse lock into several finer ones covering independent data, or replace the lock with an atomic or a lock free structure. The profile tells you which lock deserves that effort.
Key idea
Lock contention profiling reports how long threads wait on each lock, pinpointing the hot lock whose serialization caps your throughput.