Skip to content

Use simple std::mutex in the cache class #19

@morinim

Description

@morinim

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions