Add a lazy assert to prevent unnecessary function calls. #1876
Closed
klee97 wants to merge 1 commit into
Closed
Conversation
bbakerman
reviewed
May 19, 2020
| } | ||
| throw new AssertException(format(format, Arrays.stream(args).map(Supplier::get).toArray())); | ||
| } | ||
|
|
Member
There was a problem hiding this comment.
I wonder if its just a string that is laziyl supplied and the caller does the formatting
assertTrue(x == y, () -> String.format("This is the message %s, sArg1));
this way we can re-use the simple assertTrue name and migrate to it in more places
bbakerman
approved these changes
May 19, 2020
bbakerman
left a comment
Member
There was a problem hiding this comment.
I am happy with this PR. @andimarek - what do you think of the comment about assertTrue?
Member
|
We have take this ideas on this PR and taken them much further. So thanks for this PR and how it kicked us into action |
Author
|
That's exciting, thanks for making these changes! |
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.
This lazy assert is to improve the performance of
GraphQLNonNull.assertNonNullWrapping().When performance testing our execution engine that uses graphql-java,
GraphQLTypeUtil.simplePrint()stood out as a hot method. The hot code path is whensimplePrintis called to supply a parameter toAssert.assertTrue():However, the result of
simplePrintis only used if there's an error. I added a new lazy assertTrue function and used it in the above code snippet so thatsimplePrintwill only be called if it is actually used.