feat(Core/Optimization): Reduce CPU consumption by allocating sendBuffer only when it is needed. (#18628)

* feat(Core/Optimization): Reduce CPU consumption by allocating the sendBuffer only when it is needed.

* Remove whitespaces.
This commit is contained in:
Anton Popovichenko
2024-04-01 10:49:42 +02:00
committed by GitHub
parent 2aaf8474ba
commit aee2eefb92
+6 -3
View File
@@ -161,11 +161,13 @@ void WorldSocket::CheckIpCallback(PreparedQueryResult result)
bool WorldSocket::Update()
{
EncryptableAndCompressiblePacket* queued;
if (_bufferQueue.Dequeue(queued))
{
// Allocate buffer only when it's needed but not on every Update() call.
MessageBuffer buffer(_sendBufferSize);
while (_bufferQueue.Dequeue(queued))
do
{
queued->CompressIfNeeded();
ServerPktHeader header(queued->size() + 2, queued->GetOpcode());
if (queued->NeedsEncryption())
_authCrypt.EncryptSend(header.header, header.getHeaderLength());
@@ -193,10 +195,11 @@ bool WorldSocket::Update()
}
delete queued;
}
} while (_bufferQueue.Dequeue(queued));
if (buffer.GetActiveSize() > 0)
QueuePacket(std::move(buffer));
}
if (!BaseSocket::Update())
return false;