Conversation
|
Please, rebase the PR. |
e61434b to
05bb9da
Compare
oleg-jukovec
left a comment
There was a problem hiding this comment.
Thanks for the patch!
Except for the comments, everything is fine here. But let's improve the solution a bit here before merge.
Let's use the approach from the grpc-go:
https://github.com/grpc/grpc-go/blob/master/mem/buffer_pool.go
Create multiple buffers with constant byte sizes instead of the single one. Response that does not fit into these buffers should be allocated separately without a pool and without a release.
It shouldn't be copy-paste, but inspirated the go-grpc's code.
Another option is that you can correct the current comments and we will merge the PR, and you will implement logic with buffer pools in another one.
response.go
Outdated
| func createSelectResponse(header Header, body io.Reader) (*SelectResponse, error) { | ||
| resp := &SelectResponse{} | ||
| if body == nil { | ||
| resp.header = header | ||
| return resp, nil | ||
| } | ||
| if buf, ok := body.(*smallBuf); ok { | ||
| resp.header = header | ||
| resp.buf.b = buf.b | ||
| resp.buf.p = buf.p | ||
| resp.buf.ptr = buf.ptr | ||
| return resp, nil | ||
| } | ||
| data, err := io.ReadAll(body) | ||
| if err != nil { | ||
| return resp, err | ||
| } | ||
| resp.header = header | ||
| resp.buf.b = data | ||
| return resp, nil | ||
| } |
0bfee57 to
0d3cbe1
Compare
|
|
||
| // getInd returns least index of size slice, | ||
| // which is great or equal given size. | ||
| func (p *pooler) getInd(size int) int { |
slice_pool.go
Outdated
| } | ||
|
|
||
| // getInd returns least index of size slice, | ||
| // which is great or equal given size. |
There was a problem hiding this comment.
| // which is great or equal given size. | |
| // which is greater or equal given size. |
slice_pool.go
Outdated
| } | ||
|
|
||
| // getSlice returns pointer of byte slice of given size, | ||
| // also clear returning array. |
There was a problem hiding this comment.
| // also clear returning array. | |
| // also clear returning slice. |
Added method Release to Future and Response's interface, that allows to free used data directly by calling. Used to reduce allocations in `reader` function. Closes #493
0d3cbe1 to
322ad09
Compare
Added method Release to Future and Response's interface, that allows to free used data directly by calling. Used to reduce allocations in
readerfunction. Concretely, reducing alloc's in read part.Fixes #493