Conversation
1f3999a to
e37fa1b
Compare
e37fa1b to
bf0bbdc
Compare
oleg-jukovec
left a comment
There was a problem hiding this comment.
Thank you for the patch!
See issues of the current implementation, fix them and we will try again.
a15281c to
078cb7d
Compare
beda545 to
50c8953
Compare
50c8953 to
553c00f
Compare
553c00f to
3540852
Compare
|
Actualize PR/commit title/description. |
3540852 to
90195f7
Compare
test_helpers/response.go
Outdated
| } | ||
|
|
||
| func (resp *MockResponse) Release() { | ||
| // Releasing MockResponse data. |
There was a problem hiding this comment.
| // Releasing MockResponse data. | |
| // Nothing to do. |
tarantool_test.go
Outdated
| var err error | ||
|
|
||
| conn := test_helpers.ConnectWithValidation(b, dialer, opts) | ||
| defer conn.Close() | ||
|
|
||
| _, err = conn.Do( | ||
| NewReplaceRequest(spaceNo). | ||
| Tuple([]interface{}{uint(1111), "hello", "world"}), | ||
| ).Get() |
There was a problem hiding this comment.
This makes the test a bit shorter.
| var err error | |
| conn := test_helpers.ConnectWithValidation(b, dialer, opts) | |
| defer conn.Close() | |
| _, err = conn.Do( | |
| NewReplaceRequest(spaceNo). | |
| Tuple([]interface{}{uint(1111), "hello", "world"}), | |
| ).Get() | |
| conn := test_helpers.ConnectWithValidation(b, dialer, opts) | |
| defer conn.Close() | |
| _, err := conn.Do( | |
| NewReplaceRequest(spaceNo). | |
| Tuple([]interface{}{uint(1111), "hello", "world"}), | |
| ).Get() |
connection.go
Outdated
| buf := smallBuf{b: respBytes} | ||
| header, code, err := decodeHeader(conn.dec, &buf) | ||
|
|
||
| buf.tinyBuf = *respBytes |
There was a problem hiding this comment.
It seems like a separate structure for the buffer is unnecessary, since we're essentially interested in a slice here.
Especially since the tinybuf is passed by value anyway, and the original pointer is lost anyway.
So I've propose do not create a separate structure for the purpose since it makes no sense. We already can use slices.
| buf.tinyBuf = *respBytes | |
| buf.b = respBytes |
response.go
Outdated
| } | ||
|
|
||
| func (resp *baseResponse) Release() { | ||
| slicePool.Put(&resp.buf.tinyBuf) |
There was a problem hiding this comment.
We need to release the resource only if the buffer is actually allocated by ourselves in the branch:
Lines 44 to 46 in 90195f7
So we need some flag in the baseResponse structure.
| slicePool.Put(&resp.buf.tinyBuf) | |
| if resp.allocated { | |
| slicePool.Put(&resp.buf.tinyBuf) | |
| } |
response.go
Outdated
| var selectResponsePool *sync.Pool = &sync.Pool{ | ||
| New: func() interface{} { | ||
| return &SelectResponse{} | ||
| }, | ||
| } | ||
|
|
||
| func createSelectResponse(header Header, body io.Reader) (*SelectResponse, error) { | ||
| resp := selectResponsePool.Get().(*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 | ||
| return resp, nil | ||
| } | ||
| data, err := io.ReadAll(body) | ||
| if err != nil { | ||
| return resp, err | ||
| } | ||
| resp.header = header | ||
| resp.buf.b = data | ||
| return resp, nil | ||
| } | ||
|
|
||
| func (resp *SelectResponse) Release() { | ||
| resp.baseResponse.Release() | ||
| resp.baseResponse = baseResponse{} | ||
| resp.pos = nil | ||
|
|
||
| selectResponsePool.Put(resp) | ||
| } |
There was a problem hiding this comment.
Nice, but let split the PR into two parts:
- With the reader() buffers optimization.
- With the requests optimization (the selected part).
It would be much easier to merge it one by one.
|
Please, rebase & update the PR. |
90195f7 to
783a2c9
Compare
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
783a2c9 to
b2dbe37
Compare
Added method Release to Future and Response's interface, that allows to free used data directly by calling. Used to reduce allocations in creating and using slices of bytes and buffers. Concretely, reducing allocs in read part and buffer allocation of reader function.
Fixes #493
I didn't forget about (remove if it is not applicable):