Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Sync.Pool throughout for buffers #2877

Open
adriancable opened this issue Aug 15, 2024 · 1 comment
Open

Use Sync.Pool throughout for buffers #2877

adriancable opened this issue Aug 15, 2024 · 1 comment

Comments

@adriancable
Copy link
Contributor

adriancable commented Aug 15, 2024

There are 'hot' places in the code that allocate (and then need to GC) lots of small buffers, e.g. https://github.com/pion/srtp/blob/b2c2ab8afc1745b80378f66014934bd9111140aa/crypto.go#L24

Would it be better to use Sync.Pool?

Some data: pprof / top 20 shows something like this:

 5.64s  0.74% 46.12%     63.84s  8.40%  github.com/pion/srtp/v3.xorBytesCTR
 5.38s  0.71% 47.56%     10.37s  1.36%  github.com/pion/transport/v3/utils/xor.XorBytes
 4.99s  0.66% 48.22%      4.99s  0.66%  github.com/pion/transport/v3/utils/xor.xorBytesNEON32

Since the 'meat' of xorBytesCTR is xor.XorBytes, we would hope to find most of the time spent in xorBytesCTR being spent in xor.XorBytes. But this isn't the case, which points at the allocations being the biggest consumers of CPU. We could probably eliminate this via usage of Sync.Pool. There are probably other places that would benefit too, wherever small buffers are frequently allocated, not just here.

@Sean-Der
Copy link
Member

Yes please @adriancable !

We have usage in other places through out the code base. I am all for adding more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants