There is an application that heavily loads the phone's processor. All work is done in the background, but at the time of the work the user can scroll through the list. With all this, the weaker the phone, the more it slows down the UI.

I read about iOS and ran into one little article - I am not 100% sure in the article itself, but it was written correctly and correctly explained, I can’t give the link, I lost it, but briefly, it was written that when the user interacts with the UI (svaypy and etc.), the UI thread receives the highest priority, therefore the processor pays more attention to the UI thread and less freezes from it if there is none at all.

Actually, I decided to do something similar for Android , I checked a small code for the increment counter of two classes with different priorities, the one with the maximum received 430 times more CPU time, it pleased, but it was also written that for different processors the threads priorities can to be implemented in different ways, it is logical, but also one familiar authoritative person said that it was costly to drive the priorities of flows back and forth, I actually decided to ask you - what do you think about that?

Thanks in advance, I hope for constructive answers.

  • Why don't you try to make frequent priority switching in your "small" code and compare the total value of the counters with the total value of the counters without switching? This will show the "overhead" flow switching. - Pavel Krizhanovskiy
  • one
    An old article explaining the difference in rendering between Android and IOS - habrahabr.ru/post/134172 . - temq

1 answer 1

In principle, the recommendation to give the UI thread the highest priority is correct and generally accepted. The processor always runs and performs the job at the highest speed regardless of priority. Priority grows when the processor is overloaded. There are already tasks with high priority will be executed faster.

The UI thread must run quickly. Otherwise, the user feels that the application hangs. While the processor is not overloaded, the background task will also receive a maximum of processor time. However, this will not interfere with the UI, the flow of which has higher priority.

From my point of view, playing with priorities is a thankless task and, as a rule, will not give a good result. It is better to spend your time optimizing your background task (algorithm, memory, network). Maybe then the application will stop hanging?

  • I would be happy, but the problem is not in the algorithm, just such an application from the customer that you want or you don’t want, but at the same time you have to download a lot of information and the customer has to hell with it, he needs it and that’s it - BORSHEVIK