Limit memory usage, add several sync.Pool
This commit is contained in:
parent
575635753e
commit
f95788ed90
14 changed files with 277 additions and 97 deletions
|
@ -5,8 +5,11 @@ import (
|
|||
"compress/zlib"
|
||||
"crypto/sha256"
|
||||
"io/ioutil"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var idPool = sync.Pool{New: func() interface{} { return ID(make([]byte, IDSize)) }}
|
||||
|
||||
// Each lists all entries of type t in the backend and calls function f() with
|
||||
// the id and data.
|
||||
func Each(be Server, t Type, f func(id ID, data []byte, err error)) error {
|
||||
|
@ -78,7 +81,7 @@ func Uncompress(data []byte) []byte {
|
|||
// Hash returns the ID for data.
|
||||
func Hash(data []byte) ID {
|
||||
h := sha256.Sum256(data)
|
||||
id := make(ID, 32)
|
||||
id := idPool.Get().(ID)
|
||||
copy(id, h[:])
|
||||
return id
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue