Skip to content

Improved codegen in Guard APIs #3323

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

Conversation

Sergio0694
Copy link
Member

Speed improvement for #3131 and #3167

PR Type

What kind of change does this PR introduce?

  • Speed improvement

What is the current behavior?

The JIT compiler always assumes that forward branches are taken, unless it can see that the branch always throws. This doesn't happen in our throw methods, as we have a secondary ThrowHelper.Throw... method that actually creates the exceptions to throw in the correct format.

What is the new behavior?

To work around this, all the Guard conditions have been inverted to guarantee that the forward branch considered taken is the one corresponding to the successful path for the check being done. This also improves code readability, as the conditions in each Guard API are no longer inverted.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Pull Request has been submitted to the documentation repository instructions. Link:
  • Sample in sample app has been added / updated (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

@ghost
Copy link

ghost commented Jun 4, 2020

Thanks Sergio0694 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@ghost ghost assigned michael-hawker Jun 4, 2020
Copy link
Contributor

@john-h-k john-h-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Sergio0694
Copy link
Member Author

@michael-hawker Managed to fix my local branches, so there are no merge commits this time! 😄

@michael-hawker
Copy link
Member

@azchohfi @marcpems we're pretty late for 6.1, but this seems like a good optimization. We have unit tests around this code which are all passing, thoughts?

@azchohfi
Copy link
Contributor

azchohfi commented Jun 4, 2020

I'm ok merging this. There is no behavioral change. Its only performance.

@michael-hawker michael-hawker merged commit b096e6e into CommunityToolkit:master Jun 4, 2020
@michael-hawker michael-hawker added this to the 6.1 milestone Jun 4, 2020
@michael-hawker
Copy link
Member

Thanks @Sergio0694, @john-h-k, and @tannergooding for the discussion on this topic and the improvement to this new API!

@Sergio0694
Copy link
Member Author

Hey @azchohfi and @michael-hawker - thank you for the super quick review and merge! 😄
Glad the new Guard APIs will be as refined as possible right from the first public release! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants