From: Kefu Chai Date: Fri, 20 Jun 2025 09:00:59 +0000 (+0800) Subject: osd/ECExtentCache: eliminate redundant map lookups X-Git-Tag: testing/wip-hyelloji-testing-20250624.114937~3^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=f4118f892488cd2ca83ff908f092b5cd4ad82257;p=ceph-ci.git osd/ECExtentCache: eliminate redundant map lookups 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 --- diff --git a/src/osd/ECExtentCache.cc b/src/osd/ECExtentCache.cc index 1e04bc02bc2..8e8b5ac294e 100644 --- a/src/osd/ECExtentCache.cc +++ b/src/osd/ECExtentCache.cc @@ -381,11 +381,10 @@ void ECExtentCache::LRU::add(const Line &line) { shared_ptr ECExtentCache::LRU::find( const hobject_t &oid, uint64_t offset) { - Key k(offset, oid); shared_ptr 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);