aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/pprof
diff options
context:
space:
mode:
authorMartin Möhrmann <moehrmann@google.com>2019-06-10 12:56:59 +0200
committerMartin Möhrmann <moehrmann@google.com>2019-08-28 10:43:11 +0000
commit5fb74fc13853b950b5102ef26d665db97f4838fd (patch)
tree6ccf7838b033762e05656f8a4bf8b264b452f783 /src/runtime/pprof
parent37373592afe200a13d6ecf02b73a97e51beef9e1 (diff)
downloadgo-5fb74fc13853b950b5102ef26d665db97f4838fd.tar.gz
go-5fb74fc13853b950b5102ef26d665db97f4838fd.zip
runtime: reduce allocations when building pprof LabelSet
Pre-allocate the slice of labels with enough capacity to avoid growslice calls. Change-Id: I89db59ac722c03b0202e042d1f707bb041e0999f Reviewed-on: https://go-review.googlesource.com/c/go/+/181517 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/runtime/pprof')
-rw-r--r--src/runtime/pprof/label.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/runtime/pprof/label.go b/src/runtime/pprof/label.go
index 20f9cdbae6..2d92ef7e8a 100644
--- a/src/runtime/pprof/label.go
+++ b/src/runtime/pprof/label.go
@@ -60,11 +60,11 @@ func Labels(args ...string) LabelSet {
if len(args)%2 != 0 {
panic("uneven number of arguments to pprof.Labels")
}
- labels := LabelSet{}
+ list := make([]label, 0, len(args)/2)
for i := 0; i+1 < len(args); i += 2 {
- labels.list = append(labels.list, label{key: args[i], value: args[i+1]})
+ list = append(list, label{key: args[i], value: args[i+1]})
}
- return labels
+ return LabelSet{list: list}
}
// Label returns the value of the label with the given key on ctx, and a boolean indicating