-
Notifications
You must be signed in to change notification settings - Fork 26
Even faster C.Run by using no reflect at all in common cases #165
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
base: master
Are you sure you want to change the base?
Conversation
This is an alternative to PRs frankban#160 and frankban#165. It's essentially the same as PR frankban#165 except that it uses generics to reduce the amount of duplicated code. Instead of just amortizing the checking of the type, when the argument type of the function passed to `Run` is known, it bypasses the reflect-based code altogether. We don't bother implementing the optimization on pre-generics Go versions because those are end-of-lifetime anyway. I've added an implementation-independent benchmark. ``` goos: linux goarch: amd64 pkg: github.com/frankban/quicktest cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz │ base │ thisPR │ │ sec/op │ sec/op vs base │ CNewAndRunWithCustomType-8 1077.5n ± 5% 136.8n ± 6% -87.30% (p=0.002 n=6) CRunWithCustomType-8 1035.00n ± 11% 66.43n ± 3% -93.58% (p=0.002 n=6) geomean 1.056µ 95.33n -90.97% ```
This is an alternative to PRs frankban#160 and frankban#165. It's essentially the same as PR frankban#165 except that it uses generics to reduce the amount of duplicated code. Instead of just amortizing the checking of the type, when the argument type of the function passed to `Run` is known, it bypasses the reflect-based code altogether. We don't bother implementing the optimization on pre-generics Go versions because those are end-of-lifetime anyway. I've added an implementation-independent benchmark. ``` goos: linux goarch: amd64 pkg: github.com/frankban/quicktest cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz │ base │ thisPR │ │ sec/op │ sec/op vs base │ CNewAndRunWithCustomType-8 1077.5n ± 5% 136.8n ± 6% -87.30% (p=0.002 n=6) CRunWithCustomType-8 1035.00n ± 11% 66.43n ± 3% -93.58% (p=0.002 n=6) geomean 1.056µ 95.33n -90.97% ```
quicktest_test.go
Outdated
(*customT)(nil), // a custom form of testing.TB with a non-standard Run method | ||
} { | ||
tbt := reflect.TypeOf(tb) | ||
farg, err := qt.GetRunFuncSignature(tbt) |
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.
This test isn't great IMHO. Firstly, it tests GetRunFuncSignature which is an internal implementation detail (this module in general tries to test the public API as much as possible to allow later internal refactoring without changing tests). Secondly, GetRunFuncSignature won't even be invoked in most of the above cases, so I'm not sure why this is explicitly testing them.
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.
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 have now removed the commit that added that test.
Extract signature check of the Run method.
In C.Run add shortcuts to completely bypass the use of reflect for the well known cases of Run signatures with either *testing.T, *testing.B or *quicktest.C argument.
Factorize the setup of the qt.C given to the subtest. That setup is now common to the reflect version and the shortcut ones instead of being duplicated.
I've cleaned the PR:
|
In
C.Run
bypass check of the signature of theRun
method ofc.TB
for the common cases (testing.T.Run
,testing.B.Run
,quicktest.C.Run
) by using a type switch.Note: this is an alternative version of #160 and replaces it. The first 2 commits are common.
This serie of patches shows the developement process:
getRunFuncSignature
getRunFuncSignature
C.Run
to add shortcuts for common cases using a type switch