Overuse of NSView -> Alternatives?

79 views Asked by At

I having some Performance troubles with my app:

It takes more than 2 seconds to load -> So straight away I went to Apple documentation

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaPerformance/Articles/CustomViews.html#//apple_ref/doc/uid/TP40001443-CJBJIFGC

In the section named "Avoid the Overuse of Views" at the bottom I got very confused:

I indeed adding a lot of NSViews (Guess I overusing them).

" Instead, you should consider writing your own custom classes that can be managed by a higher-level NSView subclass. The drawing code of your NSView subclass can then be optimized to handle your custom objects. "

My Question is:

How can I write my own custom classes that can be managed by a higher -level NSView subclass -> any example ?

Only thing I thought was a CALayer.

Is adding CALayer subclasses are better than adding NSView ? Would it increase my poor performance a bit ?

Or there is something new to learn ?

EDIT:

Currently I have NSViews where I adding 15 NSView as a subview to them and I can add 15CALayers instead :-/

1

There are 1 answers

2
AudioBubble On BEST ANSWER

Have you profiled your App? Before ripping your view hierarchy apart, use instruments with the time profiler to find out where the time is actually being spent.

CALayers are more efficient than UIViews, and it is recommended to avoid using drawRect if you don't need to, but before resorting to a rewrite, you need to know where your App is actually spending its time.