diff --git a/httpstaticserver.go b/httpstaticserver.go index 7e946a7..06be457 100644 --- a/httpstaticserver.go +++ b/httpstaticserver.go @@ -251,11 +251,14 @@ func (s *HTTPStaticServer) hUploadOrMkdir(w http.ResponseWriter, req *http.Reque } // Note: very large size file might cause poor performance // _, copyErr = io.Copy(dst, file) + // use sync.Pool caching buf to reduce gc ratio - var bufPtr = &sync.Pool{ + bufPool := sync.Pool{ New: func() interface{} { return make([]byte, 32*1024) }, } - _, copyErr = io.CopyBuffer(dst, file, bufPtr.Get().([]byte)) + buf := bufPool.Get().([]byte) + _, copyErr = io.CopyBuffer(dst, file, buf) + defer bufPool.Put(&buf) dst.Close() // } if copyErr != nil {