Loading
perf: reduce mutex contention with early checks
Summary
Add lock-free early checks before acquiring mutex in Registry methods to reduce contention in high-throughput logging scenarios.
Changes
record_offense: Check if offense already exists before acquiring lock. Most repeated offenses will exit early without lock contention.check_for_removed_offenses: Check if baseline exists before acquiring lock. Most callsites won't have a baseline, avoiding unnecessary locking.
Uses double-checked locking pattern to ensure thread safety while reducing lock contention.
Expected Performance Improvement
- Significant reduction in mutex contention for repeated offenses
- Most log calls with deprecated fields hit the same offenses repeatedly, so the early check avoids acquiring the lock entirely
- Most callsites don't have a baseline, so
check_for_removed_offensesreturns early without locking
Relates-to: #60 (closed)