• 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: Andreas Mayer <email@hidden>
  • Date: Sun, 25 Jan 2009 08:53:09 +0100


Am 24.01.2009 um 23:29 Uhr schrieb Twisted Theory:

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.

Yes. Do not use subviews. Instead create your own view subclass and use cells.


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];
}

Why do you create a new autorelease pool here? Since this method seems to be called once for each node, you will create an additional autorelease pool every time. Also I don't see any objects created here that would go into that pool. So, unless I missed something important, you are creating and destroying 60000 additional, totally useless objects.


But you can get rid of this anyway if you use a custom view and just use your model for drawing in -drawRect:. No need to duplicate that hierarchy.


Andreas _______________________________________________

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: Creating a managed object without adding it to the context?
  • Next by Date: Re: Using the security framework
  • Previous by thread: addSubview bottleneck
  • Next by thread: Re: addSubview bottleneck
  • Index(es):
    • Date
    • Thread