-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
mem: use slice capacity instead of length, to determine whether to pool buffers or directly allocate them #7702
base: master
Are you sure you want to change the base?
Conversation
|
1ab352d
to
5d2cb0c
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #7702 +/- ##
==========================================
+ Coverage 81.80% 81.88% +0.07%
==========================================
Files 361 361
Lines 27827 27827
==========================================
+ Hits 22765 22786 +21
+ Misses 3861 3848 -13
+ Partials 1201 1193 -8
|
As the issue states, `mem.NewBuffer` would not pool buffers with a length below the pooling threshold but whose capacity is actually larger than the pooling threshold. This can lead to buffers being leaked.
5d2cb0c
to
aed354b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, modulo minor nits.
// Use the buffer's capacity instead of the length, otherwise buffers may not be reused under certain | ||
// conditions. For example, if a large buffer is acquired from the pool, but fewer bytes than the | ||
// buffering threshold are written to it, the buffer will not be returned to the pool. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can you please wrap the comment lines, here and elsewhere in this PR, to 80-cols. Thanks.
mem.NewBuffer(&b, pool).Free() | ||
|
||
if pool.data != nil { | ||
t.Fatalf("buffer not returned to pool") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: s/buffer/Buffer
Fixes #7631
As the issue states,
mem.NewBuffer
would not pool buffers with a length below the pooling threshold but whose capacity is actually larger than the pooling threshold. This can lead to buffers being leaked.RELEASE NOTES: