Skip to content
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

Optimizations/refactoring/tweaks to DispatcherQueueHelper #3498

Merged

Conversation

@Sergio0694
Copy link
Member

@Sergio0694 Sergio0694 commented Sep 22, 2020

Follow up for #3206

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Code style update (formatting)
  • Refactoring (no functional changes, no api changes)
  • Optimization

What is the new behavior?

This PR includes a number of optimizations, tweaks and refactorings to DispatcherQueueHelper:

  • Removed unnecessary null checks for function, and enabled nullability annotations. Those null checks were unnecessary since there were also other parameters that could also be null (ie. the actual DispatcherQueue) anyway, plus we'd still get an exception anyway when those instances are accessed. Instead, we now have nullability annotations to make the intent clearer.
  • Avoided the slowdown and memory allocations in case the thread already had access to the dispatcher queue, which was caused by the C# compiler (sadly) always preemptively instantiating the display class for the closure of the lambda expression used in the other branch (I made a sharplab repro here that illustrates the issue). Instead now the fallback path is moved to a separate method, so that the IL has the correct codegen.
  • Renamed the class to DispatcherQueueExtensions, since these are all extensions and not a helper class
  • Similarly, moved the class to the .Extensions namespace
  • Renamed the APIs to EnqueueAsync to mirror the TryEnqueue name of the actual API in the DispatcherQueue class. This better follows the naming convention of the class, and it's also clearer as in case users have multiple windows and different dispatching queues, there isn't really a single "UI thread" - the API is literally just enqueueing an operation on a given dispatcher queue.
  • Added a check in case TryEnqueue fails, so if that happens we now return a wrapped InvalidOperationException in the Task, whereas the previous behavior would've just caused that task to never be completed, leaving the caller just waiting forever.

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
@msftbot
Copy link
Contributor

@msftbot msftbot bot commented Sep 22, 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 🙌

@msftbot msftbot bot requested review from michael-hawker, azchohfi and Kyaa-dost Sep 22, 2020
Sergio0694 added 5 commits Sep 22, 2020
@@ -0,0 +1,251 @@
// Licensed to the .NET Foundation under one or more agreements.

This comment has been minimized.

@michael-hawker

michael-hawker Sep 23, 2020
Member

Did you git mv this file as I'm surprised it didn't mark it as a move...

This comment has been minimized.

@Sergio0694

Sergio0694 Sep 23, 2020
Author Member

I just moved it as usual through Visual Studio, not sure why it wasn't picked up 🤔
Maybe it's because I also renamed the file in the process?

This comment has been minimized.

@skendrot

skendrot Sep 23, 2020
Contributor

You must move first [commit] and then rename. You can do both in one commit

@msftbot
Copy link
Contributor

@msftbot msftbot bot commented Sep 23, 2020

This PR has been marked as "needs attention 👋" and awaiting a response from the team.

@msftbot
Copy link
Contributor

@msftbot msftbot bot commented Sep 24, 2020

This PR has been marked as "needs attention 👋" and awaiting a response from the team.

Sergio0694 added 2 commits Nov 9, 2020
@msftbot
Copy link
Contributor

@msftbot msftbot bot commented Nov 10, 2020

Hello @michael-hawker!

Because this pull request has the auto merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.
@michael-hawker michael-hawker added this to the 7.0 milestone Nov 10, 2020
@michael-hawker michael-hawker added this to In progress in Technical 7.0 via automation Nov 10, 2020
@msftbot msftbot bot added the in progress 🚧 label Nov 10, 2020
@michael-hawker
Copy link
Member

@michael-hawker michael-hawker commented Nov 10, 2020

@azchohfi think we're all good here now?

Technical 7.0 automation moved this from In progress to Reviewer approved Nov 10, 2020
@msftbot msftbot bot merged commit 9d90b62 into windows-toolkit:master Nov 10, 2020
5 checks passed
5 checks passed
Toolkit Releases Toolkit Releases succeeded
Details
Toolkit-CI Build #7.0.0-build.484+95d0520cb5 succeeded
Details
WIP Ready for review
Details
auto-merge.config.enforce No dynamic merge policies are applicable.
license/cla All CLA requirements met.
Details
Technical 7.0 automation moved this from Reviewer approved to Done Nov 10, 2020
@Sergio0694 Sergio0694 mentioned this pull request Dec 3, 2020
4 of 7 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Technical 7.0
  
Done
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.