]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/perf_counters: improve add() performance 68150/head
authorRonen Friedman <rfriedma@redhat.com>
Wed, 1 Apr 2026 05:33:21 +0000 (08:33 +0300)
committerRonen Friedman <rfriedma@redhat.com>
Tue, 7 Apr 2026 10:51:58 +0000 (10:51 +0000)
The new version is faster by 13-17% (depending
on the number of counters) compared to the
previous version.

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
src/common/perf_counters.cc

index 7fe90a2d0aac44a9465369212d1699a1a4b92c02..a3ca55286451ece86ffc4ac029e97927cefe2f8b 100644 (file)
@@ -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});
   }
 }