Skip to content

Commit

Permalink
Don't use ByteSizeLong in SendImpl loop, as it's O(number of elements)
Browse files Browse the repository at this point in the history
  • Loading branch information
qyryq committed Aug 12, 2024
1 parent 169c92d commit 9b9e3df
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,11 @@ void TWriteSessionImpl::SendImpl() {
TClientMessage clientMessage;
auto* writeRequest = clientMessage.mutable_write_request();
ui32 prevCodec = 0;

ui64 currentSize = 0;

// Send blocks while we can without messages reordering.
while (IsReadyToSendNextImpl() && clientMessage.ByteSizeLong() < GetMaxGrpcMessageSize()) {
while (IsReadyToSendNextImpl() && currentSize < GetMaxGrpcMessageSize()) {
const auto& block = PackedMessagesToSend.top();
Y_ABORT_UNLESS(block.Valid);
if (writeRequest->messages_size() > 0 && prevCodec != block.CodecID) {
Expand Down Expand Up @@ -1400,6 +1403,8 @@ void TWriteSessionImpl::SendImpl() {
moveBlock.Move(block);
SentPackedMessage.emplace(std::move(moveBlock));
PackedMessagesToSend.pop();

currentSize += writeRequest->ByteSizeLong();
}
UpdateTokenIfNeededImpl();
LOG_LAZY(DbDriverState->Log,
Expand Down

0 comments on commit 9b9e3df

Please sign in to comment.