From fa2a09c7586dc58bca641315189ef40b8b710644 Mon Sep 17 00:00:00 2001 From: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com> Date: Thu, 27 Aug 2026 11:06:48 +0100 Subject: [PATCH] perf(telemetry): increment the copy-forward total only when it is read copyForwardTotal_ is a second atomic increment beside copyForwardCount_ on the same event, kept only so a metric never goes backwards: rotate() zeroes the per-rotation tally for its log line, which leaves that counter unusable as a rate. Its only reader is MetricsRegistry.cpp:1153, through copyForwardTotal(). Guard the increment. During a rotation window every archive-served non-duplicate read pays for it, and with telemetry compiled out there is nothing to read it back. copyForwardCount_ is untouched: rotate() exchanges it for the "copied forward N archive-served reads" warning, which is real logging, not instrumentation. The virtual and the member stay declared unconditionally, so the nodestore interface has the same shape in every configuration. --- include/xrpl/nodestore/detail/DatabaseRotatingImp.h | 4 ++++ src/libxrpl/nodestore/DatabaseRotatingImp.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/include/xrpl/nodestore/detail/DatabaseRotatingImp.h b/include/xrpl/nodestore/detail/DatabaseRotatingImp.h index 9262826afe..16f5440112 100644 --- a/include/xrpl/nodestore/detail/DatabaseRotatingImp.h +++ b/include/xrpl/nodestore/detail/DatabaseRotatingImp.h @@ -108,6 +108,10 @@ private: // counter unusable as a metric: a series that drops to 0 on every swap // cannot be rated. This one only ever increases, so rate() over it reads // correctly and the two uses do not fight over one variable. + // + // Incremented only when telemetry is compiled in, since the metrics registry + // is its only reader; otherwise it stays 0 and the fetch path does one atomic + // increment less per copy-forward. std::atomic copyForwardTotal_{0}; std::shared_ptr diff --git a/src/libxrpl/nodestore/DatabaseRotatingImp.cpp b/src/libxrpl/nodestore/DatabaseRotatingImp.cpp index bece5b7d9b..a4e2e9f46d 100644 --- a/src/libxrpl/nodestore/DatabaseRotatingImp.cpp +++ b/src/libxrpl/nodestore/DatabaseRotatingImp.cpp @@ -227,8 +227,13 @@ DatabaseRotatingImp::fetchNodeObject( // Two counters, one event: the per-rotation tally that // rotate() resets for its log line, and the monotonic total // the metrics gauge reads, which must never go backwards. + // Only the first is needed for the log line, so the second + // costs an extra atomic increment per copy-forward and is + // compiled out with its only reader. copyForwardCount_.fetch_add(1, std::memory_order_relaxed); +#ifdef XRPL_ENABLE_TELEMETRY copyForwardTotal_.fetch_add(1, std::memory_order_relaxed); +#endif } writable->store(nodeObject); }