From f4118f892488cd2ca83ff908f092b5cd4ad82257 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 20 Jun 2025 17:00:59 +0800 Subject: [PATCH] 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 --- src/osd/ECExtentCache.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/osd/ECExtentCache.cc b/src/osd/ECExtentCache.cc index 1e04bc02bc2ad..8e8b5ac294ef9 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); -- 2.39.5