Skip to content

Commit

Permalink
Fix the assignment of sync buf
Browse files Browse the repository at this point in the history
  • Loading branch information
aeoluswing committed Mar 26, 2021
1 parent a60a9c4 commit d759072
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions httpstaticserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d759072

Please sign in to comment.