• 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
Re: Cocoa graphics speed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa graphics speed


  • Subject: Re: Cocoa graphics speed
  • From: Dietrich Epp <email@hidden>
  • Date: Mon, 29 Sep 2003 21:03:06 -0700

On Monday, Sep 29, 2003, at 14:05 US/Pacific, John Nairn wrote:

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?

[...]

Spool data from files: Cocoa - 8.9 sec Carbon - 9.0 sec
Fill Rectangles: Cocoa - 17.9 sec Carbon - 1.8 sec
Other stuff: Cocoa - 0.5 secs Carbon - 1.0 sec
Total time: Cocoa - 27.3 secs Carbon - 12.8 sec

Thus Carbon and Cocoa are identical except in NSFillRect() vs
FillRect() which differ by factor of 10?

You're actually comparing Quickdraw to CoreGraphics, not Cocoa to Carbon - both APIs are accessible when using either Cocoa or Carbon.

1) You might consider making your points structures rather than objects. Objective-C objects make sense for anything not particularly numerous, such as windows, controls, controllers, etc. Do you really need your points to be dynamically typed? This is most likely not a bottleneck, just a design wart.

2) NSRectFillList is probably faster than many calls to NSRectFill, otherwise it wouldn't exist.

3) If you have very many objects (you do) you might consider drawing them with OpenGL. After optimizing the hell out of my drawing routines in my Cocoa app, switching to OpenGL substantially increased performance. My application drows 1024 polygons (mostly not triangles) fast enough to keep up with the monitor's refresh rate.

In OpenGL, you can even get decent speed drawing those points one-by-one instead of using an array (which would be blindingly fast).

Additional note: In my experience, switching to the bare CoreGraphics from NSRect / NSBezierPath does not provide measurable performance benefits, if any. I could not tell which one was faster using performance measuring tools. However, CoreGraphics produces hairier code, especially when calling from Cocoa.
_______________________________________________
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.
References: 
 >Cocoa graphics speed (From: John Nairn <email@hidden>)

  • Prev by Date: Re: Reading .doc files
  • Next by Date: Address Book Helper code released to public domain
  • Previous by thread: Re: Cocoa graphics speed
  • Next by thread: Re: Cocoa graphics speed
  • Index(es):
    • Date
    • Thread