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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to