You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimize liveness tracking with indexed call trace lookup and thread-safe data structures
This commit addresses critical performance and concurrency issues in the liveness tracking system:
## Race Condition Fixes
- Fix race condition in LivenessTracker::countCallTraceReferences() by using exclusive locks
instead of shared locks during concurrent write operations
- Prevent reading partially-written tracking table entries during call trace reference counting
## Architecture Improvements
- Extract TrackingTable class from LivenessTracker for better separation of concerns
- Enable dependency injection and improved testability
- Add comprehensive thread safety tests for concurrent operations
## Performance Optimizations
- Replace O(N*M) call trace lookup complexity with O(N+M) using indexed approach
- Implement incremental index maintenance during CallTraceStorage::put() operations
- Eliminate expensive index rebuilding on every collection cycle
- Add lock-striped ConcurrentHashTable providing 64-way parallelism with cache-friendly design
## Thread-Safe Data Structures
- Create reusable ConcurrentHashTable template class inspired by Dictionary design
- Use lock striping for minimal cache line contention and optimal L2/L3 cache performance
- Support both exclusive writes and shared reads for optimal concurrent access patterns
- Implement atomic operations and proper memory barriers for correctness
## Memory Management
- Maintain call trace index incrementally during insertion (O(1) per operation)
- Avoid std::map allocations in hot paths using callback-based APIs
- Fixed-size data structures prevent memory fragmentation issues
## Testing
- Add thread safety test for TrackingTable concurrent access
- Add CallTraceStorage liveness reference preservation test
- All existing tests pass with improved performance characteristics
This optimization is critical for handling up to 256k liveness tracking entries efficiently
while maintaining correctness under high concurrent load.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
0 commit comments