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

Conversation

@rogeryi
Copy link
Contributor

@rogeryi rogeryi commented Jan 25, 2021

Manually set IO and Worker threads priority to THREAD_PRIORITY_LESS_FAVORABLE(1).

  1. From Android 8+, the priority of main thread (aka Flutter's platform thread) has been raised from THREAD_PRIORITY_DEFAULT(0) to THREAD_PRIORITY_VIDEO(-10) by system;
  2. The UI/Raster/IO and Worker threads are created by platform thread and inherit its priority;
  3. Flutter raised priority of UI and Raster threads to -1 and -5, but leave IO and Worker threads untouched;
  4. The current result is IO and Worker threads have extreme high priority (-10), much higher than UI and Raster thread;
  5. The image decoding and mipmap generation on IO and Worker threads are very time consuming and usually block the UI and Raster threads when App loading bunch of images, especially on low end devices;

So manually set IO and Worker threads to an appropriate background priority such as THREAD_PRIORITY_LESS_FAVORABLE(1) will be a good move, it will work nicely on both Android 8+ and lower version.

List which issues are fixed by this PR. You must list at least one issue.

The background threads - IO and Worker threads, have much higher priority than UI and Raster thread, and easy to make them blocked and cause jank.

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

No

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.
  • The reviewer has submitted any presubmit flakes in this PR using the engine presubmit flakes form before re-triggering the failure.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@google-cla
Copy link

google-cla bot commented Jan 25, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@rogeryi
Copy link
Contributor Author

rogeryi commented Jan 25, 2021

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

1 similar comment
@google-cla
Copy link

google-cla bot commented Jan 25, 2021

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@chinmaygarde
Copy link
Member

cc @dnfield. This seem like a sound patch. Though, we should followup on an iOS implementation as well.

@dnfield
Copy link
Contributor

dnfield commented Jan 28, 2021

This does not impact the Dart worker threads, which should likely get similar prioritization.

@dnfield
Copy link
Contributor

dnfield commented Jan 28, 2021

(not that it should block this patch)

@rogeryi
Copy link
Contributor Author

rogeryi commented Jan 29, 2021

This does not impact the Dart worker threads, which should likely get similar prioritization.

Dart worker inherit Flutter UI thread's -1 priority, lower it to 1 maybe better, although not as necessary as this

Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

We should figure out a way to generalize this to all platforms. In the meantime, I think this is fine for Android.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes platform-android 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.

5 participants