Permalink
Browse files

Create slice with predefined capacity

Each append caused a runtime.growslice since the slice had no initial
capacity and so we had to grow the slice on appends.

Since we know the capacity, we can make the slice with this info
to avoid allocations
  • Loading branch information...
prashantv committed Jan 21, 2016
1 parent b26d6c4 commit 9fb6e8db2884b20cb7f5a576f2dc4e36f477af2f
Showing with 3 additions and 2 deletions.
  1. +3 −2 stats/reporter.go
View
@@ -36,13 +36,14 @@ func RecordTimer(name string, tags map[string]string, d time.Duration) {
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.
var keyOrder []string
keyOrder := make([]string, 0, 4)
if _, ok := tags["host"]; ok {
keyOrder = append(keyOrder, "host")
}
keyOrder = append(keyOrder, "endpoint", "os", "browser")
parts := []string{name}
parts := make([]string, 1, 5)
parts[0] = name
for _, k := range keyOrder {
v, ok := tags[k]
if !ok || v == "" {

0 comments on commit 9fb6e8d

Please sign in to comment.