The cache hash table currently uses shared locks (std::shared_mutex) to enable concurrent reads and exclusive writes. However, internal tests conducted on standard workstations indicate that the overhead of std::shared_mutex may outweigh its benefits, particularly when compared to std::mutex. This appears to be due to the short critical section in the find member function, which might not justify the complexity of read-write locks.
Observations
- On systems with a limited number of CPUs or hardware threads, the contention for
std::shared_mutex may introduce significant overhead, reducing the performance advantage of concurrent reads.
- On systems with a greater number of CPUs or hardware threads, the benefits of
std::shared_mutex may become more apparent, as contention is distributed across more resources.
Cross-Platform Considerations
- Differences between operating systems, particularly Linux and Windows, may lead to varying performance characteristics for
std::shared_mutex due to differences in underlying implementations.
- Further testing is required to evaluate these differences and ensure consistent performance across platforms.
Recommendations
Benchmarking
- Perform detailed benchmarks comparing
std::shared_mutex and std::mutex on systems with varying CPU and thread counts.
- Evaluate performance differences across Linux and Windows platforms.
Simplification
Consider replacing std::shared_mutex with std::mutex if benchmarks show consistent performance improvements and the benefits of concurrent reads are negligible.
References:
The cache hash table currently uses shared locks (
std::shared_mutex) to enable concurrent reads and exclusive writes. However, internal tests conducted on standard workstations indicate that the overhead ofstd::shared_mutexmay outweigh its benefits, particularly when compared tostd::mutex. This appears to be due to the short critical section in the find member function, which might not justify the complexity of read-write locks.Observations
std::shared_mutexmay introduce significant overhead, reducing the performance advantage of concurrent reads.std::shared_mutexmay become more apparent, as contention is distributed across more resources.Cross-Platform Considerations
std::shared_mutexdue to differences in underlying implementations.Recommendations
Benchmarking
std::shared_mutexandstd::mutexon systems with varying CPU and thread counts.Simplification
Consider replacing
std::shared_mutexwithstd::mutexif benchmarks show consistent performance improvements and the benefits of concurrent reads are negligible.References: