Let's say I have a GUI application that performs long computations for the user (for example, video processing). Should I increase the priority of my computation process/thread to make it run faster? What would be the harm in doing so?
-
I already know all about this stuff. This question is intended as a FAQ, because I see so many well-intentioned programmers getting it all wrong. – Emile Cormier Sep 07 '15 at 19:37
-
I might even learn a thing or two. :-) – Emile Cormier Sep 07 '15 at 19:38
-
priority gives (might) more chance in context switching, beside having two thread(gui and video-process) doesn't mean 50-50 process share – Sep 07 '15 at 19:40
3 Answers
If you have a piece of processing that requires five minutes of processor time, it is going to take five minutes to process. On a non-busy system, where that is the only application running it is unlikely to make a lot of difference.
However, on a system that has other tasks, then you're going to steal processing time from those, and the user is likely to think that your system is making their computer hang.
If you have a long running task, you're actually better reducing the priority, so that the user can get on with doing other things. This is the principle behind multitasking...

- 11,887
- 6
- 38
- 74
Generally no. It's rare that someone would prefer a non-responsive system during a long calculation than a responsive system where the calculation takes a tiny bit longer.
There are also a variety of reasons that increased priority can result in the calculation actually taking longer. For example, increased pre-emption of other tasks can blow out the CPU caches, making those tasks take longer. This can slow down the task you care about for a variety of reasons, including increased inter-core contention.
You raise priority when you can't tolerate unpredictable or increased latency.

- 179,497
- 17
- 214
- 278
Well, if you spend more time processing video they there may be less resources available for reading it from disk, for example.
The only real way is to test...

- 19,079
- 3
- 51
- 79