NSView -drawRect optimization
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