Skip to content
Snippets Groups Projects
Commit 69a187c5 authored by Manish R Jain's avatar Manish R Jain
Browse files

Create a sync.Pool for entry struct. This removes newOrExisting in...

Create a sync.Pool for entry struct. This removes newOrExisting in uid/assigner.go from memory profiler.
parent 1e1a1cc9
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,11 @@ import (
var glog = x.Log("uid")
var lmgr *lockManager
var uidStore *store.Store
var eidPool = sync.Pool{
New: func() interface{} {
return new(entry)
},
}
type entry struct {
sync.Mutex
......@@ -63,7 +68,7 @@ func (lm *lockManager) newOrExisting(xid string) *entry {
if e, ok := lm.locks[xid]; ok {
return e
}
e := new(entry)
e := eidPool.Get().(*entry)
e.ts = time.Now()
lm.locks[xid] = e
return e
......@@ -78,6 +83,7 @@ func (lm *lockManager) clean() {
if e.isOld() {
count += 1
delete(lm.locks, xid)
eidPool.Put(e)
}
}
lm.Unlock()
......@@ -181,9 +187,8 @@ func assignNew(pl *posting.List, xid string, instanceIdx uint64,
}
func stringKey(xid string) []byte {
buf := new(bytes.Buffer)
buf.WriteString("_uid_")
buf.WriteString("|")
var buf bytes.Buffer
buf.WriteString("_uid_|")
buf.WriteString(xid)
return buf.Bytes()
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment