Re: NSView -drawRect optimization
Re: NSView -drawRect optimization
- Subject: Re: NSView -drawRect optimization
- From: Paul Bruneau <email@hidden>
- Date: Thu, 14 Feb 2008 09:26:50 -0500
On Feb 12, 2008, at 6:51 PM, Erik Buck wrote:
You are drawing way too much each time you draw. You only need to
draw graphics that fall within the rect passed to -drawRect:, and
you can narrow it down even farther using - (void)
getRectsBeingDrawn:(const NSRect **)rects count:(NSInteger *)
count. Not drawing things that don't need to be drawn is the
biggest optimization you will get. (snip)
Thank you Erik for an amazing reply. I will reply to some of your
questions even though they might be rhetorical :) In addition I will
be learning about everything that you told me and thanks again for
your reply.
Your method of determining where drawing time is being spent is
probably effective, but it's way too much work. Just use Shark or
Sampler along with Quartz Debug. Apple provides some of the best
profiling tools anywhere and they're free.
I know you are right and I tried Shark but I could not get an idea of
where in my code the time was being spent. I need to learn more about
these tools, for sure.
Why don't OrderStep instances draw themselves ?
The best answer is "Because I have spent 20 years or so coding in
Procedural Land and only 6 months in Cocoa Land!" :) I just saw -
drawRect and said to myself "here is where I draw my view" but I do
know from what I have read that I am not thinking "objectively"
enough so I will implement something like the code you graciously
wrote for me.
I will be surprised if you can't make you drawing 100x faster, and
1000x faster is within the realm of possibility.
10x would be great :)
There is a lengthy chapter on graphics optimization in "Cocoa
Programming" http://www.cocoaprogramming.net/ You can download
the examples including a Tetris game without buying the book. The
optimization examples are in Appendix B: Optimizing and Finding
Memory Leaks.
I'm going to go read that chapter right now. I recently bought the
digital version of your book because you didn't print enough paper
ones :) but I haven't read it yet.
_______________________________________________
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