Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace.Step() performs an unnecessary alloc #25244

Merged
merged 1 commit into from
May 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/util/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down