pion / mediadevices

Go implementation of the MediaDevices API.
https://pion.ly/
MIT License
528 stars 121 forks source link

Optimise ToI420 conversion by using sync.Pool #424

Closed EmrysMyrddin closed 1 year ago

EmrysMyrddin commented 2 years ago

Since #418, the I420 conversion have been slow down because 2 new buffers are allocated for each frame converted.

The idea is to use a sync.Pool to minimise the overhead of creating new []byte:

This way we should limit the garbage collector pressure and the time needed to fill the []byte with 0 values at creation.

neversi commented 1 year ago

Could I have a try to resolve this issue?

neversi commented 1 year ago

Is there need to add sync.Pool? Whenever there is the call to ReaderFunc, there is also mutex Lock, so here we could use closure instead as there is no concurrent access to the buffers.

neversi commented 1 year ago

Can we close the issue?

at-wat commented 1 year ago

done by https://github.com/pion/mediadevices/pull/473