Skip navigation.
 
mlNSView -drawRect optimization
FROM : Paul Bruneau
DATE : Tue Feb 12 23:02:46 2008

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

Related mailsAuthorDate
mlNSView -drawRect optimization Paul Bruneau Feb 12, 23:02
mlRe: NSView -drawRect optimization John Stiles Feb 12, 23:17
mlRe: NSView -drawRect optimization Peter Ammon Feb 12, 23:31
mlRe: NSView -drawRect optimization Greg Titus Feb 12, 23:39
mlRe: NSView -drawRect optimization Graham Feb 12, 23:49
mlRe: NSView -drawRect optimization Erik Buck Feb 13, 00:51
mlRe: NSView -drawRect optimization Paul Bruneau Feb 13, 14:22
mlRe: NSView -drawRect optimization Paul Bruneau Feb 13, 14:22
mlRe: NSView -drawRect optimization John Stiles Feb 13, 18:41
mlRe: NSView -drawRect optimization Paul Bruneau Feb 14, 14:47
mlRe: NSView -drawRect optimization Paul Bruneau Feb 14, 15:13
mlRe: NSView -drawRect optimization Paul Bruneau Feb 14, 15:26
mlRe: NSView -drawRect optimization Kyle Sluder Feb 14, 16:43