• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSView -drawRect optimization
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSView -drawRect optimization


  • Subject: NSView -drawRect optimization
  • From: Paul Bruneau <email@hidden>
  • Date: Tue, 12 Feb 2008 17:02:46 -0500

Hi-

I have just deployed my first Cocoa app which is a scheduling program used by one user in my company. I'm very proud of it as a first app but I want to make it a little better.

It has a subclass of NSView where I draw all of the "orderSteps" which are the pieces of work that are required to complete all the orders on our shop floor. Here is a screenshot of the view in its window:
http://special-lite.com/satellite/scheduleWindow.png


The user clicks and drags all those little rectangles around in order to optimize the production. They "bump" each other out of the way. They limit each others' motion when there is no more room to bump, etc. There are 226 rectangles on the screenshot, but during busy times there might be 500-700.

My only concern with it is the frames per second draw speed of the view (it's all done in -drawRect). I have done pretty good testing to remove individual segments of code from the loop in order to see what is taking the time:

- As developed, it draws at about 5.9 frames per second on my 2.66 ghz Mac Pro (user is on a 24" iMac, almost as fast)
- Removing the orderStep draw loop completely gives me about 25 fps


Here is my loop that draws each orderStep on the view. This loop gets called once for each workCenter that you see on the left side of the view.

http://objc.pastebin.com/m4fe1a694

In the code are comments that tell how many fps were gained for each fragment of code that I commented out. All the fragments do not add up to the 19fps difference so I can assume that my math is horrible or that the addition of each fragment makes other things take longer in some way. One thing I know for sure is that -addToolTipRect takes forever!

If anyone likes looking at newbie code for stupid things, now is your chance. I'll happily take any tips, comments, or even derision. My biggest fear is to hear "There's nothing you can do about it--stuff takes time" to which I would respond, "Then how does Blizzard do it!? I know they are drawing more than 226 rectangles!"

Thank you
_______________________________________________

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


  • Follow-Ups:
    • Re: NSView -drawRect optimization
      • From: "Kyle Sluder" <email@hidden>
    • Re: NSView -drawRect optimization
      • From: Greg Titus <email@hidden>
    • Re: NSView -drawRect optimization
      • From: Peter Ammon <email@hidden>
    • Re: NSView -drawRect optimization
      • From: John Stiles <email@hidden>
  • Prev by Date: Re: NSCollectionView questions
  • Next by Date: Re: KVC and KVO for arrays
  • Previous by thread: Fwd: IOKit.framework - The Destruction of my Project
  • Next by thread: Re: NSView -drawRect optimization
  • Index(es):
    • Date
    • Thread