From: Ronen Friedman Date: Wed, 1 Apr 2026 05:33:21 +0000 (+0300) Subject: common/perf_counters: improve add() performance X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F68150%2Fhead;p=ceph.git common/perf_counters: improve add() performance The new version is faster by 13-17% (depending on the number of counters) compared to the previous version. Signed-off-by: Ronen Friedman --- diff --git a/src/common/perf_counters.cc b/src/common/perf_counters.cc index 7fe90a2d0aac..a3ca55286451 100644 --- a/src/common/perf_counters.cc +++ b/src/common/perf_counters.cc @@ -48,10 +48,18 @@ void PerfCountersCollectionImpl::add(PerfCounters *l) m_loggers.insert(l); - const auto rc_name = l->get_name(); - for (auto& dt: l->m_data) { - const auto path = rc_name + "." + dt.name; - by_path[path] = {&dt, l}; + const auto& rc_name = l->get_name(); + std::string path; + // +1 for the dot, +64 for the counter name (48 is the current + // max length) + const auto reserve_size = rc_name.size() + 1 + 64; + for (auto& dt : l->m_data) { + std::string path; + path.reserve(reserve_size); + path.assign(rc_name); + path += '.'; + path += dt.name; + by_path.insert_or_assign(std::move(path), PerfCounterRef{&dt, l}); } }