NSTimer's heavy on MIPS?

  • Hi,

    I'm new to Cocoa and Mac dev in general.  I'm following an online
    tutorial to create a simple game in RubyCocoa, and have since ported
    it to Objective-C.  It uses NSTimer to set up a 1/60th second
    update.  In the timer callback, I update the positions of about 10-15
    objects, and redraw the 800x600 view (not opaque).  I find that these
    NSTimer's are sucking quite a bit of the Window Server's MIPs (30% on
    a Mac Pro with 4 cores).  The objects themselves each only require 1
    or 2 bezier paths, so I'm not sure what's taking all of the CPU.

    Are NSTimer's just not meant to be used at 60fps?  Perhaps NSTimer
    has a heavy overhead in the NSRunLoop?

    Thanks,
    Dave.
  • On Oct 25, 2006, at 7:33 PM, David Brackman wrote:

    > It uses NSTimer to set up a 1/60th second update.  In the timer
    > callback, I update the positions of about 10-15 objects, and redraw
    > the 800x600 view (not opaque).  I find that these NSTimer's are
    > sucking quite a bit of the Window Server's MIPs (30% on a Mac Pro
    > with 4 cores).  The objects themselves each only require 1 or 2
    > bezier paths, so I'm not sure what's taking all of the CPU.

    It's not the timers, it's what you do with them.  The window server
    is going to flush all of your changes to the display as you redraw
    and flush the view content.  The drawing of the objects takes place
    in your application, but the compositing of all those pixels happens
    in the window server.

    800 x 600 pixels * 60 repaints per second == 28,800,000 pixels per
    second that are recomputed and pushed to the display.
  • On 26 okt 2006, at 04.33, David Brackman wrote:

    > Are NSTimer's just not meant to be used at 60fps?  Perhaps NSTimer
    > has a heavy overhead in the NSRunLoop?

    You should get acquainted with Apples fantastic - and free! -
    performance tools, and in particular Shark. When you have performance
    problems, never guess at what the problem could be, always measure.

    <http://developer.apple.com/documentation/Performance/Conceptual/
    PerformanceOverview/index.html
    >

    <http://developer.apple.com/tools/sharkoptimize.html>
    <http://developer.apple.com/tools/performance/
    optimizingwithsystemtrace.html
    >

    j o a r
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today