-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Optimise runtime for passing tests #933
Conversation
Helper() in the standard Go runtime fetches a stack trace from the runtime, so is slow for calls that are made many times. Helper() only makes a difference if the call throws an error, so move it after the test in straightforward cases.
I like the idea behind this PR but there are several things that need to happen.
|
This information is not in CONTRIBUTING.md. Would you like a PR to move it from README.md and add a link? |
Yea, that makes sense. Thank you
… On 28 Apr 2020, at 05:29, Bryan Boreham ***@***.***> wrote:
run the go generate ./... function
This information is not in CONTRIBUTING.md. Would you like a PR to move it from README.md and add a link?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I didn't realise I have re-pushed without that commit and with a benchmark. Before (best of 5):
After:
I didn't get this bit. Could you explain more? |
3379aa5
to
043a780
Compare
Almost everything in
That looks great!
What I meant is that we could change the unit tests of some (or all if you're so inclined) of the functions you optimised to use |
What I originally did in Maybe it would be more fruitful to generate a copy of the assert code rather than call the function, because otherwise we‘re calling |
Yes, but if you re-run
Agreed but that would be a much bigger change in |
No, this PR does not change |
Yes, but if I'm not mistaken, running |
Didn’t happen for me. Note I did have a problem at the beginning that I had hand-edited |
I see. Something isn’t right then since the auto generation should create the require.go file if I remember correctly.
… On 29 Apr 2020, at 03:24, Bryan Boreham ***@***.***> wrote:
Didn’t happen for me.
The generation is based off the function signature, and I haven’t changed any of those.
Note I did have a problem at the beginning that I had hand-edited require.go, which caused an error saying I needed to re-generate, but I’ve removed that commit from this PR.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Yes the generator creates |
I see. This is obviously a problem then. Doesn't seem right that we change a function in |
@bboreham , I have found the cause/issue. In This is fine in my opinion since the The only important factor to this is that it will change a large amount of code, so if you're willing to have a thorough look and make sure that everything is being called correctly, I'll be happy to double-check and approve if all is fine :) |
I think that would mean failures are reported inside |
I see, very good point. I missed that. I'm very happy to merge it in its current format then. I guess optimisation of some parts is better than none :) Thank you for your effort and time! |
Summary
Move some calls to
testing.Helper()
to reduce overhead.Changes
Move call to
Helper()
after the check in various straightforwardassert
cases.Short-circuit- deferred till another timerequire.NoError()
andrequire.NoErrorf()
so they do not callHelper()
when no error is found.Motivation
Helper()
in the standard Go runtime fetches a stack trace from the runtime, so is slow for calls that are made many times. However,Helper()
only makes a difference if the call throws an error, so we can avoid that overhead in many cases which are otherwise cheap.Related issues
#766 (not a full fix)