Skip to content

RetransmissionBuffer: Avoid needless allocations when storing and removing items - #1997

Merged
jmillan merged 4 commits into
v3from
retransmission_buffer_fixes
Oct 16, 2026
Merged

jmillan merged 4 commits into
v3from
retransmission_buffer_fixes

Conversation

@jmillan

@jmillan jmillan commented Oct 16, 2026

Copy link
Copy Markdown
Member
  • FillItem() is replaced with CreateItem(), which constructs the item in place instead of default constructing it and assigning its members afterwards.

  • Clear() and RemoveOldest() no longer call Item::Reset() before deleting the item. ~Item() already destroys sharedPacket (which is what decreases the RTP packet shared pointer counter), so the call was redundant. Worse, Item::Reset() does not reset the item in place but replaces sharedPacket with a newly constructed one, allocating yet another shared state just to destroy it immediately after.

…emoving items

- `FillItem()` is replaced with `CreateItem()`, which constructs the item
  in place instead of default constructing it and assigning its members
  afterwards.

- `Clear()` and `RemoveOldest()` no longer call `Item::Reset()` before
  deleting the item. `~Item()` already destroys `sharedPacket` (which is
  what decreases the RTP packet shared pointer counter), so
  the call was redundant. Worse, `Item::Reset()` does not reset the item
  in place but replaces `sharedPacket` with a newly constructed one,
  allocating yet another shared state just to destroy it immediately
  after.
@jmillan
jmillan requested a review from ibc October 16, 2026 09:43

@ibc ibc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the Item::Reset() method or can we remove it?

@jmillan

jmillan commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

Do we need the Item::Reset() method or can we remove it?

We don't. Only used in tests, I already commented this in the past. I'll remove it here.

@ibc

ibc commented Oct 16, 2026

Copy link
Copy Markdown
Member

Do we need the Item::Reset() method or can we remove it?

We don't. Only used in tests, I already commented this in the past. I'll remove it here.

Does Reset() make sense in the tests? It's useful for something? If so we can make the method only public with #ifdef MS_TEST and private otherwise. There are some classes in SCTP and BWE with that trick in their .hpp.

@jmillan

jmillan commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

Does Reset() make sense in the tests? It's useful for something? If so we can make the method only public with #ifdef MS_TEST and private otherwise. There are some classes in SCTP and BWE with that trick in their .hpp.

It does not. There's no reason to test something that is never used.

@jmillan

jmillan commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

Indeed I though you were referring to SharedPacket::Reset() which is also not used anywhere but in tests.

@ibc

ibc commented Oct 16, 2026

Copy link
Copy Markdown
Member

Indeed I though you were referring to SharedPacket::Reset() which is also not used anywhere but in tests.

Ok some trick applies there.

@jmillan
jmillan merged commit 45ef4b9 into v3 Oct 16, 2026
50 checks passed
@jmillan
jmillan deleted the retransmission_buffer_fixes branch October 16, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants