开发者

Performance of self.view for NSCollectionViewItem

I'm looking at using an NSCollectionView for a photo library application, which will allow browsing of 10,000+ images. I'm not sure if NSCollectionView is the best thing for this, or if I should be looking at other methods, so feel free to throw your 2 cents in if you have an opinion.

Anyway, in the (custom) class holding the NSCollectionViewItem, when a specific bound value is updated, I call a method on the item's view.

Problem is, just accessing [self view] is taking an 开发者_开发问答exorbitant amount of time. This was demonstrated by breaking the call to [self view] into another method and running instrumentation over it. The following method

- (NSBox*)getBox {
    return (NSBox*)[self view];
}

takes about 100 times more processing time that any other single method. Yes, it's called many times, but if I change to return self, rather than self.view, the getBox method doesn't even appear in the processing list.

Any ideas on why this should be the case?


Why not use Image Kit's IKImageBrowserView, which is basically an iPhoto-like image browser?

There's the ImageKitDemo and ImageBrowser sample projects.

Regarding the performance issue with [self view], it might be that the collection view is being loaded lazily from the nib each time, and this call to [self view] is what's causing another instance to be instantiated from memory or from disk. While I haven't used NSCollectionView myself, my gut feeling is that there's probably going to be a greater overhead with numerous NSViews compared to IKImageBrowserView which uses the standard coupling of an NSView with an NSCell-like reusable drawing mechanism to help improve performance.

See Avoid the Overuse of Views:

"A good example of when to use custom objects is a photo browser that displays thumbnail images of hundreds or even thousands of photos. Wrapping each photo in an NSView instance would both be prohibitively expensive and inefficient. Instead, you would be better off by creating a lightweight class to manage one or more photos and a custom view to manage that lightweight class."

(In many places, a single NSView subclass will re-use an NSCell subclass to help implement the drawing of its contents. In this respect, the NSCell basically acts as a little "drawing machine").

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜