-
Notifications
You must be signed in to change notification settings - Fork 0
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
Stop querying for stack frames multiple times on CallerInfo() #7
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with 50. It would be nice if n==50 that we added a "more callers ignored" or something as the last "caller" just as a warning to users.
That totally makes sense - let me see if I can figure out how to actually test that before I commit to adding it, though |
I didn't realize what repo I was in - this is also fine to panic as this will be all tests |
and if you're going to upstream this change, presumably, they'd like a version where you loop and get all of them as the previous version does - just 10-50 at a time |
Yeah I think I'm actually just going to do that now that I think about it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! A small nit - I think it's marginally easier to read and marginally less instructions but I'm good either way.
(would be nice to have a test to prove that it works for bigger stack depths - not sure if that's easy to do or hard?)
assert/assertions.go
Outdated
pcs := make([]uintptr, stackFrameBufferSize) | ||
offset := 1 | ||
n := runtime.Callers(offset, pcs) | ||
maybeMore := true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybeMore := n == stackFrameBufferSize
and you can tuck it behind the n==0 early return a couple lines down
assert/assertions.go
Outdated
} | ||
offset += stackFrameBufferSize | ||
n = runtime.Callers(offset, pcs) | ||
if n < stackFrameBufferSize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same nit here
It's hard because they explicitly opt stack frames from the testify packages out of accumulation 🙃 |
Summary
CallerInfo
to useruntime.Callers()
to pull the stack instead of repeatedly callingruntime.Caller()
Changes
Callers()
instead of repeatedCaller
invocationsframes.Next()
iteratorMotivation
Caller
contributing a CPU cost of 7660ms out of a total cost of 13740msRelated issues