]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: a faster version of SnapMapper::get_prefix()
authorRonen Friedman <rfriedma@redhat.com>
Tue, 2 Aug 2022 08:40:18 +0000 (08:40 +0000)
committerRonen Friedman <rfriedma@redhat.com>
Wed, 3 Aug 2022 06:00:34 +0000 (06:00 +0000)
Using fmtlib, and treating the size of uint64_t as a known
quantity.
Per google-bench - the new version is 10% to 20% faster.

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

index 804213b1f264461d6830a7f0ed2681868dc3a579..26ace62a7382e469e8459979845b50b11f7216b3 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include "SnapMapper.h"
+#include <fmt/printf.h>
 
 #define dout_context cct
 #define dout_subsys ceph_subsys_osd
@@ -99,13 +100,11 @@ int OSDriver::get_next(
 
 string SnapMapper::get_prefix(int64_t pool, snapid_t snap)
 {
-  char buf[100];
-  int len = snprintf(
-    buf, sizeof(buf),
-    "%lld_%.*X_",
-    (long long)pool,
-    (int)(sizeof(snap)*2), static_cast<unsigned>(snap));
-  return MAPPING_PREFIX + string(buf, len);
+  static_assert(sizeof(pool) == 8, "assumed by the formatting code");
+  return fmt::sprintf("%s%lld_%.16X_",
+                     MAPPING_PREFIX,
+                     pool,
+                     snap);
 }
 
 string SnapMapper::to_raw_key(