Even faster C.Run by using no reflect at all in common cases#165
Open
dolmen wants to merge 3 commits intofrankban:masterfrom
Open
Even faster C.Run by using no reflect at all in common cases#165dolmen wants to merge 3 commits intofrankban:masterfrom
dolmen wants to merge 3 commits intofrankban:masterfrom
Conversation
rogpeppe
added a commit
to rogpeppe-contrib/quicktest
that referenced
this pull request
Aug 1, 2023
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% ```
rogpeppe
added a commit
to rogpeppe-contrib/quicktest
that referenced
this pull request
Aug 1, 2023
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% ```
Contributor
Author
rogpeppe
reviewed
Aug 2, 2023
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) |
Contributor
There was a problem hiding this comment.
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.
Contributor
Author
Contributor
Author
There was a problem hiding this comment.
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.
Contributor
Author
|
I've cleaned the PR:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
C.Runbypass check of the signature of theRunmethod ofc.TBfor 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:
getRunFuncSignaturegetRunFuncSignatureC.Runto add shortcuts for common cases using a type switch