Re: Prioritizing drawing of the important stuff
Re: Prioritizing drawing of the important stuff
- Subject: Re: Prioritizing drawing of the important stuff
- From: Alastair Houghton <email@hidden>
- Date: Mon, 31 Oct 2016 09:53:08 +0000
On 29 Oct 2016, at 10:37, Jonathan Taylor <email@hidden> wrote:
>
> This is a bit of a general question, but hopefully people may have some suggestions. I've got some drawing code that synthesizes an image in a window, which will change in response to sliders (e.g. changing the camera perspective). My problem is how to make it so that the redrawing of the image is as responsive as possible as the slider moves.
>
> At the moment I just respond to KVO notifications from the slider by redrawing. This works fairly well. However, after further development work my program is now a bit more complicated. Effectively, I have two images, one of which is expensive to draw and one less so. What I would like is to have the quick-to-draw one update fairly often, and the more expensive one at lower priority. Does anyone have any suggestions about how to achieve this?
A couple of comments:
1. Have you checked how frequently the KVO notifications fire as you move the slider? If the answer is more than 60 times a second, you should probably think about triggering only the *first* view update from the KVO notification, with subsequent view updates running on a timer until the slider has stopped moving.
2. For the “slow” image, you could run it at lower priority, but as you have noticed that might result in starvation if there is a higher priority thread that is always ready to run. An alternative would be to run in a normal priority thread; if that uses up too much CPU (for instance), you could consider explicitly sleeping occasionally (with e.g. nanosleep()). Another option that sometimes works well in these kinds of situations is to start a timer when the slider first moves, resetting it every time you get a move notification, and only do the expensive drawing when the timer completes; you can obviously adjust this policy for your specific circumstances.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden