From d75b6e70cc91060fcf00ed66d6e8ae489ef6a886 Mon Sep 17 00:00:00 2001 From: Aman Sharma Date: Tue, 21 May 2024 12:33:49 -0700 Subject: [PATCH] Call Clock::now only once in writeConnectionDataToSocket Summary: The time between iterations is not significant, so we can just call `Clock::now` once in the beginning and reuse the same value. I ran a canary with some counters to get an idea of the amount of time between the start of the first iteration and the end of the last iteration (see D57510979), and: * Edge p100: 1500 us * olb p100: 1900 us * Edge p99: 413 us * olb p99: 396 us The wins we're seeing are 0.13% relative CPU. Reviewed By: kvtsoy Differential Revision: D57594650 fbshipit-source-id: 9d0f827564179745cd83eb6ca211df68d3f23f8b --- quic/api/QuicTransportFunctions.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/quic/api/QuicTransportFunctions.cpp b/quic/api/QuicTransportFunctions.cpp index 930e7bd57..e708f5d4c 100644 --- a/quic/api/QuicTransportFunctions.cpp +++ b/quic/api/QuicTransportFunctions.cpp @@ -1529,6 +1529,8 @@ WriteQuicDataResult writeConnectionDataToSocket( } }; + quic::TimePoint sentTime = Clock::now(); + while (scheduler.hasData() && ioBufBatch.getPktSent() < packetLimit && ((ioBufBatch.getPktSent() < batchSize) || writeLoopTimeLimit(writeLoopBeginTime, connection))) { @@ -1581,7 +1583,7 @@ WriteQuicDataResult writeConnectionDataToSocket( connection, std::move(result->packetEvent), std::move(result->packet->packet), - Clock::now(), + sentTime, folly::to(ret.encodedSize), folly::to(ret.encodedBodySize), false /* isDSRPacket */);