mediasoup icon indicating copy to clipboard operation
mediasoup copied to clipboard

ObjectPoolAllocator

Open jmillan opened this issue 3 years ago • 11 comments

This is an extract from a bigger "Memory Optimizations" PR #675

It contains only the ObjectPoolAllocator part with a few exceptions:

  • RtpPacket::Parse() does return a RtpPacket instance. In #675 it returned a shared pointer but since shared pointers are just needed for cloned packets (for retransmission), the former method does not need to create one.
  • RtcpCompoundPacket is left as it was. This is, a new one is created when needed (this will be enhanced in a separate PR).

As per my tests I'm not seeing much difference with this and v3. There is maybe some noticeable CPU enhancement.

Please @nazar-pc , @Hartigan give it a try and instrument this if possible to see how it enhances comparing to v3. I'll do some more testing just to make sure this addition is worth it.

Performed performance unit tests:

Parsed RtpPackets ObjectPoolAllocator (sec) new/delete (sec)
10K 0.0028 0.0039
100K 0.027 0.038
1M 0.26 0.33
Cloned RtpPackets ObjectPoolAllocator (sec) new/delete (sec)
10K 0.0034 0.0049
100K 0.033 0.049
1M 0.33 0.48

ObjectPoolAllocator is definitely more performant as it reuses memory instead of freeing & re-allocating it.

jmillan avatar Sep 07 '22 15:09 jmillan

NOTE: Currently measuring the CPU time differences with pools VS new/delete.

jmillan avatar Sep 09 '22 08:09 jmillan

Converted to draft while re-testing re-profiling. Feel fee to try it out and review.

jmillan avatar Sep 09 '22 08:09 jmillan

@Hartigan please send multiple comments as a review together rather than individually, it will reduce number of GitHub notifications everyone receives.

nazar-pc avatar Sep 30 '22 19:09 nazar-pc

Which is the status of this PR?

ibc avatar Jan 26 '23 11:01 ibc

It's ready to merge. It's working properly. Even though we may want to enrich he pool allocator in the future is a good starting point.

jmillan avatar Jan 26 '23 12:01 jmillan

Ok?

ibc avatar Jan 26 '23 13:01 ibc

Reminder: this PR needs love.

ibc avatar Mar 29 '23 16:03 ibc

Yes, it's on my TODO

jmillan avatar Mar 29 '23 18:03 jmillan

I'll revive this PR for the new year.

jmillan avatar Dec 15 '23 15:12 jmillan