From 0e05f704f36271603a6051ebcc77ab7ac43be361 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Fri, 6 May 2016 00:02:25 -0400 Subject: [PATCH] Trace.Step() performs an unnecessary ref Allocates more objects than necessary. --- pkg/util/trace.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/util/trace.go b/pkg/util/trace.go index a6b92234596..ed9da94b328 100644 --- a/pkg/util/trace.go +++ b/pkg/util/trace.go @@ -32,15 +32,19 @@ type traceStep struct { type Trace struct { name string startTime time.Time - steps []*traceStep + steps []traceStep } func NewTrace(name string) *Trace { - return &Trace{name, time.Now(), make([]*traceStep, 0)} + return &Trace{name, time.Now(), nil} } func (t *Trace) Step(msg string) { - t.steps = append(t.steps, &traceStep{time.Now(), msg}) + if t.steps == nil { + // traces almost always have less than 6 steps, do this to avoid more than a single allocation + t.steps = make([]traceStep, 0, 6) + } + t.steps = append(t.steps, traceStep{time.Now(), msg}) } func (t *Trace) Log() {