• 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: addSubview bottleneck
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: addSubview bottleneck


  • Subject: Re: addSubview bottleneck
  • From: douglas welton <email@hidden>
  • Date: Sun, 25 Jan 2009 19:17:09 -0500

Hi Josh,

I would echo Andreas' advice and tell you to not use NSViews to accomplish this task.

I would suggest that you take a closer look at the problem domain and re-factor along the lines of the data you manage and the drawn representation of that data. NSViews are great containers for drawing, but at what point does your program need to display 60,000 things on the screen at once? Does the user actually perceive the drawing as 60,000 objects or as one object? If, most of the time, a user will only see a subset of the 60,000 objects, then perhaps you should rethink how you are doing your drawing.

My suggestion is that you keep your 60,000 objects in some "datasource- like" object that can be queried by the Custom View that actually does the drawing. Let your custom view draw only those objects that are visible. If the objects you are drawing can be handled by an existing NSCell type ( e.g., an image cell or text cell), then use a copy of that cell type to do your drawing, otherwise just do the drawing yourself.

regards,

douglas

On Jan 24, 2009, at 5:29 PM, Twisted Theory wrote:

Hi,

I am constructing an application that draws rooted trees (graphs with a
distinguished 'first' node) by creating an NSView subclass for each node and
adding them as subviews of the graph view.


There is a big problem when the number of nodes in the tree is large: adding
the subviews takes a very long time. For example, one of my trees has
around 60,000 nodes. It takes about 1.5 seconds to create all of the
objects, and about 200 seconds to add them as subviews.


Can anyone suggest a way to speed the process up? Multithreading didn't
really improve matters.


Each node keeps track of its child nodes in an NSArray, and the subview
addition is recursive:


- (void) add
{
NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];


[[parent superview] addSubview:self];
for (Vertex * child in children)
[child performSelectorOnMainThread:@selector(add) withObject:nil
waitUntilDone:NO];
//[child add];


   [autoreleasepool release];
}

Thanks,

Josh
_______________________________________________

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

_______________________________________________

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


References: 
 >addSubview bottleneck (From: Twisted Theory <email@hidden>)

  • Prev by Date: Re: NSArray KVC proxy
  • Next by Date: Re: NSArray KVC proxy
  • Previous by thread: Re: addSubview bottleneck
  • Next by thread: How to know that DOMHTMLElement is loaded?
  • Index(es):
    • Date
    • Thread