Permalink
Browse files

Add disabled pool for bytes.Buffer

Add code for sync.Pool. It did not run faster in this case, most likely
due to the use of defer.

Since it doesn't improve performance, the bytes.Buffer code is left in
commented.
  • Loading branch information...
prashantv committed Jan 21, 2016
1 parent a2f0a61 commit 02630f1c5bcf2fbdc034eca393ab34071221d1ef
Showing with 12 additions and 0 deletions.
  1. +12 −0 stats/reporter.go
View
@@ -4,6 +4,7 @@ import (
"bytes"
"flag"
"fmt"
"sync"
"time"
)
@@ -33,6 +34,12 @@ func RecordTimer(name string, tags map[string]string, d time.Duration) {
}
}
var bufPool = sync.Pool{
New: func() interface{} {
return &bytes.Buffer{}
},
}
func addTagsToName(name string, tags map[string]string) string {
// The format we want is: host.endpoint.os.browser
// if there's no host tag, then we don't use it.
@@ -42,6 +49,11 @@ func addTagsToName(name string, tags map[string]string) string {
}
keyOrder = append(keyOrder, "endpoint", "os", "browser")
// We tried to pool the object, but perf didn't get better.
// It's most likely due to use of defer, which itself has non-trivial overhead.
// buf := bufPool.Get().(*bytes.Buffer)
// defer bufPool.Put(buf)
// buf.Reset()
buf := &bytes.Buffer{}
buf.WriteString(name)
for _, k := range keyOrder {

0 comments on commit 02630f1

Please sign in to comment.