Skip to content

Store *[]byte in bufferPool to avoid allocation on Put#368

Merged
JoTurk merged 2 commits into
pion:masterfrom
asnyatkov:fix/bufferpool-pointer-optimization
Mar 27, 2026
Merged

Store *[]byte in bufferPool to avoid allocation on Put#368
JoTurk merged 2 commits into
pion:masterfrom
asnyatkov:fix/bufferpool-pointer-optimization

Conversation

@asnyatkov

Copy link
Copy Markdown
Contributor

Description

sync.Pool boxes values into any (interface{}). Storing []byte directly causes the 24-byte slice header to be heap-allocated on every Put(). Storing *[]byte avoids this since the pointer is already on the heap.

This is the same pattern used in Go stdlib (fmt.pp, encoding/json).

sync.Pool boxes values into any (interface{}). Storing []byte directly
causes the 24-byte slice header to be heap-allocated on every Put().
Storing *[]byte avoids this since the pointer is already on the heap.

This is the same pattern used in Go stdlib (fmt.pp, encoding/json).
@codecov

codecov Bot commented Mar 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.42%. Comparing base (4bcdae3) to head (34d24cd).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
session_srtcp.go 60.00% 1 Missing and 1 partial ⚠️
session_srtp.go 71.42% 1 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (66.66%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #368      +/-   ##
==========================================
- Coverage   82.63%   82.42%   -0.22%     
==========================================
  Files          19       19              
  Lines        1457     1462       +5     
==========================================
+ Hits         1204     1205       +1     
- Misses        140      142       +2     
- Partials      113      115       +2     
Flag Coverage Δ
go 82.42% <66.66%> (-0.22%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JoTurk JoTurk merged commit a6e6e9b into pion:master Mar 27, 2026
16 of 18 checks passed
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