1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-07-30 14:43:05 +03:00

Create IOBuf on the stack using folly::IOBuf::wrapBufferAsValue for body

Summary: This is similar to the previous commit. We use a stack-based IOBuf instead of allocating one on the heap. This saves CPU because allocations/deallocations on the stack are a lot cheaper.

Reviewed By: hanidamlaj

Differential Revision: D53101722

fbshipit-source-id: dd59a7eca6498db19472a62f954db3e2f2f27a42
This commit is contained in:
Aman Sharma
2024-01-29 15:19:12 -08:00
committed by Facebook GitHub Bot
parent 5a131b6f04
commit 303c405e10
13 changed files with 102 additions and 98 deletions

View File

@ -151,7 +151,7 @@ TEST_F(QuicPacketSchedulerTest, CryptoPaddingInitialPacket) {
auto result = cryptoOnlyScheduler.scheduleFramesForPacket(
std::move(builder), conn.udpSendPacketLen);
auto packetLength = result.packet->header.computeChainDataLength() +
result.packet->body->computeChainDataLength();
result.packet->body.computeChainDataLength();
EXPECT_EQ(conn.udpSendPacketLen, packetLength);
}
@ -184,7 +184,7 @@ TEST_F(QuicPacketSchedulerTest, PaddingInitialPureAcks) {
auto result = acksOnlyScheduler.scheduleFramesForPacket(
std::move(builder), conn.udpSendPacketLen);
auto packetLength = result.packet->header.computeChainDataLength() +
result.packet->body->computeChainDataLength();
result.packet->body.computeChainDataLength();
EXPECT_EQ(conn.udpSendPacketLen, packetLength);
}
@ -218,7 +218,7 @@ TEST_F(QuicPacketSchedulerTest, InitialPaddingDoesNotUseWrapper) {
auto result = acksOnlyScheduler.scheduleFramesForPacket(
std::move(builder), conn.udpSendPacketLen - cipherOverhead);
auto packetLength = result.packet->header.computeChainDataLength() +
result.packet->body->computeChainDataLength();
result.packet->body.computeChainDataLength();
EXPECT_EQ(conn.udpSendPacketLen, packetLength);
}
@ -251,7 +251,7 @@ TEST_F(QuicPacketSchedulerTest, CryptoServerInitialPadded) {
auto result = scheduler.scheduleFramesForPacket(
std::move(builder1), conn.udpSendPacketLen);
auto packetLength = result.packet->header.computeChainDataLength() +
result.packet->body->computeChainDataLength();
result.packet->body.computeChainDataLength();
EXPECT_EQ(conn.udpSendPacketLen, packetLength);
}
@ -284,7 +284,7 @@ TEST_F(QuicPacketSchedulerTest, PadTwoInitialPackets) {
auto result = scheduler.scheduleFramesForPacket(
std::move(builder1), conn.udpSendPacketLen);
auto packetLength = result.packet->header.computeChainDataLength() +
result.packet->body->computeChainDataLength();
result.packet->body.computeChainDataLength();
EXPECT_EQ(conn.udpSendPacketLen, packetLength);
increaseNextPacketNum(conn, PacketNumberSpace::Initial);
@ -303,7 +303,7 @@ TEST_F(QuicPacketSchedulerTest, PadTwoInitialPackets) {
auto result2 = scheduler.scheduleFramesForPacket(
std::move(builder2), conn.udpSendPacketLen);
packetLength = result2.packet->header.computeChainDataLength() +
result2.packet->body->computeChainDataLength();
result2.packet->body.computeChainDataLength();
EXPECT_EQ(conn.udpSendPacketLen, packetLength);
}
@ -335,7 +335,7 @@ TEST_F(QuicPacketSchedulerTest, CryptoPaddingRetransmissionClientInitial) {
auto result = scheduler.scheduleFramesForPacket(
std::move(builder), conn.udpSendPacketLen);
auto packetLength = result.packet->header.computeChainDataLength() +
result.packet->body->computeChainDataLength();
result.packet->body.computeChainDataLength();
EXPECT_EQ(conn.udpSendPacketLen, packetLength);
}
@ -398,7 +398,7 @@ TEST_F(QuicPacketSchedulerTest, CryptoWritePartialLossBuffer) {
auto result = cryptoOnlyScheduler.scheduleFramesForPacket(
std::move(builder), conn.udpSendPacketLen);
auto packetLength = result.packet->header.computeChainDataLength() +
result.packet->body->computeChainDataLength();
result.packet->body.computeChainDataLength();
EXPECT_LE(packetLength, 25);
EXPECT_TRUE(result.packet->packet.frames[0].asWriteCryptoFrame() != nullptr);
EXPECT_FALSE(conn.cryptoState->initialStream.lossBuffer.empty());
@ -806,7 +806,9 @@ TEST_F(QuicPacketSchedulerTest, CloneSchedulerUseNormalSchedulerFirst) {
folly::IOBuf(
folly::IOBuf::CopyBufferOp::COPY_BUFFER,
"if you are the dealer"),
folly::IOBuf::copyBuffer("I'm out of the game"));
folly::IOBuf(
folly::IOBuf::CopyBufferOp::COPY_BUFFER,
"I'm out of the game"));
return SchedulingResult(folly::none, std::move(builtPacket));
}));
RegularQuicPacketBuilder builder(
@ -831,7 +833,7 @@ TEST_F(QuicPacketSchedulerTest, CloneSchedulerUseNormalSchedulerFirst) {
*folly::IOBuf::copyBuffer("if you are the dealer"),
result.packet->header));
EXPECT_TRUE(folly::IOBufEqualTo{}(
*folly::IOBuf::copyBuffer("I'm out of the game"), *result.packet->body));
*folly::IOBuf::copyBuffer("I'm out of the game"), result.packet->body));
}
TEST_F(QuicPacketSchedulerTest, CloneWillGenerateNewWindowUpdate) {
@ -992,7 +994,7 @@ TEST_F(QuicPacketSchedulerTest, CloningSchedulerWithInplaceBuilderFullPacket) {
auto result = scheduler.scheduleFramesForPacket(
std::move(builder), conn.udpSendPacketLen);
auto bufferLength = result.packet->header.computeChainDataLength() +
result.packet->body->computeChainDataLength();
result.packet->body.computeChainDataLength();
EXPECT_EQ(conn.udpSendPacketLen, bufferLength);
updateConnection(
conn,
@ -1063,7 +1065,7 @@ TEST_F(QuicPacketSchedulerTest, CloneLargerThanOriginalPacket) {
conn.ackStates.appDataAckState.largestAckedByPeer.value_or(0));
auto packetResult = scheduler.scheduleFramesForPacket(
std::move(builder), conn.udpSendPacketLen - cipherOverhead);
auto encodedSize = packetResult.packet->body->computeChainDataLength() +
auto encodedSize = packetResult.packet->body.computeChainDataLength() +
packetResult.packet->header.computeChainDataLength() + cipherOverhead;
EXPECT_EQ(encodedSize, conn.udpSendPacketLen);
updateConnection(
@ -2402,14 +2404,14 @@ TEST_F(QuicPacketSchedulerTest, ShortHeaderPaddingWithSpaceForPadding) {
std::move(builder2), conn.udpSendPacketLen);
auto headerLength1 = result1.packet->header.computeChainDataLength();
auto bodyLength1 = result1.packet->body->computeChainDataLength();
auto bodyLength1 = result1.packet->body.computeChainDataLength();
auto packetLength1 = headerLength1 + bodyLength1;
auto expectedPadding1 =
(conn.udpSendPacketLen - (inputDataLength1 + headerLength1)) %
paddingModulo;
auto headerLength2 = result2.packet->header.computeChainDataLength();
auto bodyLength2 = result2.packet->body->computeChainDataLength();
auto bodyLength2 = result2.packet->body.computeChainDataLength();
auto packetLength2 = headerLength2 + bodyLength2;
auto expectedPadding2 =
(conn.udpSendPacketLen - (inputDataLength2 + headerLength2)) %
@ -2460,7 +2462,7 @@ TEST_F(QuicPacketSchedulerTest, ShortHeaderPaddingNearMaxPacketLength) {
std::move(builder), conn.udpSendPacketLen);
auto headerLength = result.packet->header.computeChainDataLength();
auto bodyLength = result.packet->body->computeChainDataLength();
auto bodyLength = result.packet->body.computeChainDataLength();
auto packetLength = headerLength + bodyLength;
@ -2515,7 +2517,7 @@ TEST_F(QuicPacketSchedulerTest, ShortHeaderPaddingMaxPacketLength) {
std::move(builder), conn.udpSendPacketLen);
auto headerLength = result.packet->header.computeChainDataLength();
auto bodyLength = result.packet->body->computeChainDataLength();
auto bodyLength = result.packet->body.computeChainDataLength();
auto packetLength = headerLength + bodyLength;
@ -2554,7 +2556,7 @@ TEST_F(QuicPacketSchedulerTest, ImmediateAckFrameSchedulerOnRequest) {
auto result = immediateAckOnlyScheduler.scheduleFramesForPacket(
std::move(builder), conn.udpSendPacketLen);
auto packetLength = result.packet->header.computeChainDataLength() +
result.packet->body->computeChainDataLength();
result.packet->body.computeChainDataLength();
EXPECT_EQ(conn.udpSendPacketLen, packetLength);
}
@ -2590,7 +2592,7 @@ TEST_F(QuicPacketSchedulerTest, ImmediateAckFrameSchedulerNotRequested) {
auto result = immediateAckOnlyScheduler.scheduleFramesForPacket(
std::move(builder), conn.udpSendPacketLen);
auto packetLength = result.packet->header.computeChainDataLength() +
result.packet->body->computeChainDataLength();
result.packet->body.computeChainDataLength();
// The immediate ACK scheduler was not triggered. This packet has no frames
// and it shouldn't get padded.
EXPECT_LT(packetLength, conn.udpSendPacketLen);