On Sat, Dec 20, 2008 at 9:22 AM, Oleg Krupnov <[email protected]> wrote: > Here is how I arrived at the conclusion that NSRectFill is the > bottleneck. (I cannot show the code because it's spread over objects). > > The slowness of redraw is only noticeable when I drag the mouse, e.g. > to resize an object in the custom view. I see that update of the > resized object is always late after the actual position of the mouse > pointer, and the latency is sometimes pretty great to not be excused. > Especially when the size of the rectangle to be updated is large.
When doing things like this you always need to coalesce events before drawing. If you're triggering a redraw for every event then you always leave yourself open to problems. The moment that your events come in faster than your redraws can occur, you lose. This doesn't necessarily only happen when your code is really slow. Maybe you find a user on a really slow computer. Maybe the computer starts to swap. Maybe the computer is running 300 CPU intensive processes simultaneously. Maybe the mouse is sending events at 120Hz and the screen is only refreshing at 60Hz. A simple way to do this is to avoid calling setNeedsDisplay: (or its friends) directly from your event handler. Instead start a timer with some suitably small interval, and set a flag. If the flag is already set, don't start the timer, it's already been started. When the timer fires, invalidate the view and clear the flag. Once you've done this, if it's still too slow then it will manifest as simply being unsmooth, but it will still follow your mouse movements in realtime, which is a substantial improvement. If it's still too slow at that point then you can see what else might be going on and try to fix it from a better position. Mike _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
