Switches CallerInfo to use runtime.Callers() to pull the stack instead of repeatedly calling runtime.Caller()
Changes
Buffer 10 stack frames at a time by switching to a series of calls to Callers() instead of repeated Caller invocations, because there is a cost to querying the stack
Iterate over the frames with the frames.Next() iterator
Motivation
We heavily use mocks at DevotedHealth and the repeated calls to pull the stack were flagging as a contributor when I profiled some of our slow tests - see example of Caller contributing a CPU cost of 7660ms out of a total cost of 13740ms
Summary
CallerInfo
to useruntime.Callers()
to pull the stack instead of repeatedly callingruntime.Caller()
Changes
Callers()
instead of repeatedCaller
invocations, because there is a cost to querying the stackframes.Next()
iteratorMotivation
Caller
contributing a CPU cost of 7660ms out of a total cost of 13740msRelated issues