Commit caf6f06f authored by Robert Bailey's avatar Robert Bailey

Merge pull request #25244 from smarterclayton/trace_alloc

Trace.Step() performs an unnecessary alloc
parents 2f65d2e6 0e05f704
...@@ -32,15 +32,19 @@ type traceStep struct { ...@@ -32,15 +32,19 @@ type traceStep struct {
type Trace struct { type Trace struct {
name string name string
startTime time.Time startTime time.Time
steps []*traceStep steps []traceStep
} }
func NewTrace(name string) *Trace { 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) { 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() { func (t *Trace) Log() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment