Stop prioritizing foreground threads

asked 2016-03-10 10:39:06 +0200

koolas gravatar image

updated 2016-03-10 11:31:03 +0200

Upp15 gravatar image

Windows NT used to have the slider to configure how to prioritize foreground over background threads. You could set to zero to not prioritize at all. From my experience prioritizing foreground threads works only well with single threaded applications. In old times apps were single threaded, but since internet browser age is no longer true. Right now most apps require network communication, and frontend uses minimum compared to all background threads. Frontend tends to block until network dwlivers data, so if you prioritize fronted you get glitches - the ux sucks! it feels like ui hang ups, just because it's waiting for background thread, to which you gave low priority because its background. If I open Opera and start loading some big web page, and I switch task, opera will not be loading that page in background as fast as it could.

My recommendation is to remove foreground thread prioritization totally. I'm ok with 10fps ui, and I'm not ok with ui hanging in the middle of me typing login or url!

edit retag flag offensive close delete

Comments

btw My experience with Sailfish factory default was better from performance poit of view than Sailfish 2+

koolas ( 2016-03-10 10:40:46 +0200 )edit
1

I can also suggest another solution: pin foreground threads to cpu core 0, and background threads to cpu1. I bet you get three things out of that: - smooth ui - work progress in background - lower battery usage

koolas ( 2016-03-10 10:45:57 +0200 )edit
1

@koolas - would it really lower battery usage? At the most it may remain the same, if not higher ...

sifartech ( 2016-03-10 11:23:46 +0200 )edit

Aren't Linux and Windows different in this regard that Windows uses co-operative scheduling? In Windows a thread may be hogging up the execution time. The user needs a way to prevent/adjust the hanging and a slider is a way to do it.

alloj ( 2016-03-10 11:33:36 +0200 )edit
1

It doesn't matter whether we talk about Linux or Windows or any other OS. The problem is OS independed - it's strictly logical. You've got 2 CPU cores and you prioritize foreground threads. I don't know what is the criteria you use to tell "foreground thread" from "background thread". What if there are dependencies between foreground thread and background thread, i.e. foreground thread is waiting for work done by background thread. What if you have many foreground threads, and because you prioritize them background threads never get to CPU?

I can suggest following solution: - foreground threads are prioritized over background threads when selected CPU core is #1 - background threads are prioritized over foreground threads when selected CPU core is #2

This way you will never starve either type of threads, because you pre-select CPU core for each type. You also don't waste CPU cores, because foreground threads are still allowed to run on core #2, and background threads are allowed to run on core #1. But in high load situation core #1 will serve foreground threads, and core #2 will server background threads. Also in case of low load situation core #1 would rather sleep, and only core #2 would do work, and this way we'd save some battery when phone is in the pocket playing DI.FM.

Can you at least think about it, try out the idea somehow and see for yourself what results you'd get?

koolas ( 2016-03-11 02:09:19 +0200 )edit