Skip to content

Commit

Permalink
Reduce contention on cache hash table mutex
Browse files Browse the repository at this point in the history
Previously, the mutex was unnecessarily held while destroying cache
entries in the case that `total_bytes_limit == 0`, leading to contention
on the mutex in the case that destruction is expensive (e.g. release a
large memory allocation).

PiperOrigin-RevId: 688801635
Change-Id: I347f5c6312920bb6b4ae4b3396dbd6414654dfaa
  • Loading branch information
jbms authored and copybara-github committed Oct 23, 2024
1 parent 2b818e7 commit 5927385
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tensorstore/internal/cache/cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ void StrongPtrTraitsCacheEntry::decrement_impl(
cache->reference_count_.fetch_sub(CacheImpl::kNonEmptyShardIncrement,
std::memory_order_relaxed);
}
// Release lock before invoking entry destructor, as that may be
// expensive.
lock = {};
delete entry_impl;
}
} else {
Expand Down

0 comments on commit 5927385

Please sign in to comment.