You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/07/05 00:59:31 UTC
[GitHub] [dubbo-go-hessian2] tylitianrui commented on a change in pull request #271: reuse allocated buffer
tylitianrui commented on a change in pull request #271:
URL: https://github.com/apache/dubbo-go-hessian2/pull/271#discussion_r663583148
##########
File path: encode.go
##########
@@ -56,6 +54,22 @@ func (e *Encoder) Clean() {
e.refMap = make(map[unsafe.Pointer]_refElem, 7)
}
+// ReuseBufferClean reuse the Encoder for a new object encoding.
+// it reuse allocated buffer and reduce memory-allocation.
+func (e *Encoder) ReuseBufferClean() {
+ var buffer []byte
+ if len(e.buffer) <= 128 {
Review comment:
i am sorry, i made a typo. `cap` , not `len`.
if not check the buffer capacity. there is a risk of memory leak. for example, an encoder encodes an huge object (eg: 100K ), the allocated room of buffer is also so big. generally, most of object is not such huge. it causes most of buffer room is not used and not GC . it is
> 128 may be too small for most situation,i suggest to change it to 512,or allow user to chang it by ‘hessian.SetReuseBufferSize(int)’
good idea
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org