Re: Cocoa graphics speed
Re: Cocoa graphics speed
- Subject: Re: Cocoa graphics speed
- From: Nat! <email@hidden>
- Date: Tue, 30 Sep 2003 01:45:09 +0200
Am Montag, 29.09.03 um 23:05 Uhr schrieb John Nairn:
The drawRect method of my custom view draws many elements (100's to
100,000) and each element has a stroke method. Drawing these elements
is twice as slow in Cocoa app then in prior version of the app in
Carbon. But it is much worse --- most of the graphics time in Cocoa is
taken by filling a rectangle with a color and that graphics call
(NSRectFill()) is TEN times slower than the comparable Carbon
FillRect(). Is there any way to speed up graphics in Cocoa?
Here is the central, slow method in Cocoa app
- (void)stroke:(id)sender
{
float radius=[sender radius];
NSRect ptRect;
[color set]; // color for element
ptRect=NSMakeRect((float)pt.x-radius,(float)pt.y-radius,
2.*radius,
2.*radius);
NSRectFill(ptRect);
}
The Carbon code that is 10 times faster (despite needing extra
calculation - a conversion to pixel coordinates) is:
I just coded something fairly similiar (though only with 16384
rectangles). The speed was frustrating. AFAIK you can't do much about
it in Cocoa. You can do a little better if you have the possibility to
cache the color, and only set them if it changes. I was only drawing
black and white blocks and caching the color and avoiding the -set, got
me somewhere like a 30% speedup. But a 30% faster snail is still no
sprinter...
In the end I used a lot of little views (64) instead of one big view
and I "hand draw" everything into one NSBitmapImageRep or one view and
blit those during -drawRect. I went from 0.5 fps to "quite sufficient"
(>15 fps) with that approach :) It doesn't look quite as pretty though.
One big problem of Cocoa (and maybe even Quartz) with drawing lots of
little stuff is that there is too much locking going on. Everytime you
call NSRectFill there is a internally lock opened and closed :), which
kills your performance. A big improvement would be to expose the locks
(probably in graphics context) and feature some non-locking calls, but
that's something only Apple can do.
Ciao
Nat!
------------------------------------------------------
Die Generation nach uns wird sich mit der Inhaltsleere
herumschlagen muessen und am Ende an der Langeweile zu
Grunde gehen. -- Augstein
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.