Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Mar 3, 2022

Currently windows does not set a thread priority, this may be the cause of pauses in the raster thread - outside of occasionally blocking on SwapBuffers.

Expose a new field on the custom task runners embedder struct which allows users to set the thread priority on the current thread given an enum describing the purpose of that thread.

Does not expose the thread name

Also wires this support into the windows embedding

@flutter-dashboard flutter-dashboard bot added the embedder Related to the embedder API label Mar 3, 2022
break;
}
case fml::Thread::ThreadPriority::RASTER: {
if (SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS) != 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't correct since this refers to the process priority, which we may need to consider as well

@jonahwilliams jonahwilliams changed the title draft example of windows thread priority Add support for setting thread priority in embedder.h and update windows embedding to do so Mar 3, 2022
@jonahwilliams jonahwilliams marked this pull request as ready for review March 3, 2022 19:53
@jonahwilliams jonahwilliams requested a review from dnfield March 3, 2022 20:28
EXPECT_EQ(strcmp(args->dart_entrypoint_argv[1], "arg2"), 0);
EXPECT_NE(args->platform_message_callback, nullptr);
EXPECT_NE(args->custom_task_runners, nullptr);
EXPECT_NE(args->custom_task_runners->thread_priority_setter, nullptr);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs better tests naturally...

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some tests where you call the setter function with different priority levels and check the priority of the current thread after each call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, when I did that I noticed I was setting process priority level 🤦

Copy link
Contributor

Choose a reason for hiding this comment

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

The added test is good, but can you also call the thread_priority_setter here to make sure it's the one we think it is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// mark thread priorities and success/failure.
switch (priority) {
case FlutterThreadPriority::kBackground: {
SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be SetThreadPriority/GetCurrentThread?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, just realized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

Suggestion for test, seems like we are setting process class rather than thread priority here.

@jonahwilliams jonahwilliams requested a review from dnfield March 3, 2022 21:12
@dnfield
Copy link
Contributor

dnfield commented Mar 3, 2022

Somehow the license bot is unhappy? Otherwise LGTM.

@jonahwilliams
Copy link
Contributor Author

Might be because I branched off of master instead of main

@jonahwilliams jonahwilliams added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Mar 3, 2022
@fluttergithubbot fluttergithubbot merged commit 6c67716 into flutter:main Mar 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

embedder Related to the embedder API platform-windows waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants