From 915882b2939237125e732a01e87c622cb13ff95b Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Sun, 4 Oct 2026 06:02:44 -0400 Subject: [PATCH] [Perf] (Server): time records only when the per-frame statistics are on --- MobileGL/MG_Remote/Server/ServerLoop.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/MobileGL/MG_Remote/Server/ServerLoop.cpp b/MobileGL/MG_Remote/Server/ServerLoop.cpp index 08d5cfb4..f713f84e 100644 --- a/MobileGL/MG_Remote/Server/ServerLoop.cpp +++ b/MobileGL/MG_Remote/Server/ServerLoop.cpp @@ -1085,6 +1085,7 @@ namespace MobileGL::MG_Remote::Server { static std::uint64_t sFrameRecords = 0; static std::uint64_t sFrameIndex = 0; Uint64 applied = 0; + const bool timed = ServerFrameStatsEnabled(); for (;;) { if (SessionLatched()) break; if (m_windowRequests.load(std::memory_order_acquire) != 0) { @@ -1093,15 +1094,21 @@ namespace MobileGL::MG_Remote::Server { } bool corrupt = false; const bool popped = consumer.ApplyOne( - [this, &applier](const Transport::RingRecordView& record) { - const auto applyStarted = std::chrono::steady_clock::now(); - applier.ApplyOne(record); + [this, &applier, timed](const Transport::RingRecordView& record) { // P65ServerFrame: timed around the ONE call that is the server's work, and // summed across the drains a frame spans. See the block above DrainRing's loop. - sFrameApplyNs += static_cast( - std::chrono::duration_cast( - std::chrono::steady_clock::now() - applyStarted) - .count()); + // Only when the line is on: two clock reads per record were a measurable part + // of a record's cost. + if (timed) { + const auto applyStarted = std::chrono::steady_clock::now(); + applier.ApplyOne(record); + sFrameApplyNs += static_cast( + std::chrono::duration_cast( + std::chrono::steady_clock::now() - applyStarted) + .count()); + } else { + applier.ApplyOne(record); + } ++sFrameRecords; // P9 W3, F2: outside the apply timing above; 0 in every run that is not F2. if (m_testLogFloodLines != 0) FloodLogForTest(m_testLogFloodLines);