]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
osd/ECExtentCache: eliminate redundant map lookups
authorKefu Chai <tchaikov@gmail.com>
Fri, 20 Jun 2025 09:00:59 +0000 (17:00 +0800)
committerKefu Chai <tchaikov@gmail.com>
Fri, 20 Jun 2025 10:00:49 +0000 (18:00 +0800)
Replace contains() + at() pattern with single find() call to avoid
double lookup overhead. Previously checked map.contains(key) then
used map.at(key), which performs two hash table lookups for the
same operation.

Now uses map.find() and checks the returned iterator against end(),
accessing the value directly from the iterator when found.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/osd/ECExtentCache.cc

index 1e04bc02bc2ad47c51cb1379ec9aa452da62aae3..8e8b5ac294ef9aba236d32642aad209b4a789550 100644 (file)
@@ -381,11 +381,10 @@ void ECExtentCache::LRU::add(const Line &line) {
 
 shared_ptr<shard_extent_map_t> ECExtentCache::LRU::find(
     const hobject_t &oid, uint64_t offset) {
-  Key k(offset, oid);
   shared_ptr<shard_extent_map_t> cache = nullptr;
   std::lock_guard lock{mutex};
-  if (map.contains(k)) {
-    auto &&[lru_iter, c] = map.at(k);
+  if (auto found = map.find({offset, oid}); found != map.end()) {
+    auto &&[lru_iter, c] = found->second;
     cache = c;
     auto it = lru_iter; // Intentional copy.
     erase(it, false);