Hello List,

I'm having a problem with a performance problem in NSKeyedArchiver which I can't find a cause for. Let me first describe the data I'm storing:

It's a simple object hierarchy consisting of the following

Root  custom < NSCoding > compliant object
  |-- ANodes  (NSMutableArray)
       |-- A  (custom < NSCoding > compliant object
           |- NNodes  (NSMutableArray)
                |- N  (custom < NSCoding > compliant object
                   |- 4 double ivars

There is 1 root object with 120 A objects each containing 1000-3000 N objects, that makes about 200k N objects in the hierarchy.

For some reason N is causing the performance problem, but in a very strange way. The encodeWithCoder method looks like this:

----------------------------------------------------------------------
- (void)encodeWithCoder:(NSCoder *)encoder
{
    [encoder encodeDouble:v1 forKey:@"v1"];
    [encoder encodeDouble:v2 forKey:@"v2"];
    [encoder encodeDouble:v3 forKey:@"v3"];
    [encoder encodeDouble:v4 forKey:@"v4"];
}
----------------------------------------------------------------------

v1, v2, v3, v4 are all ivars of N.

It is not the encoding itself that takes so long (the whole hierarchy is encoded in less than one second), it's when I call [archiver finishEncoding] in my document's dataOfType: which looks like this:

----------------------------------------------------------------------
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
    NSMutableData *data = [[NSMutableData alloc] init];

NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData: data];
    [archiver setOutputFormat: NSPropertyListBinaryFormat_v1_0];

    [archiver encodeObject: root forKey:@"root"];

    [archiver finishEncoding];

    [archiver release];

    [data autorelease];

    if ((!data) && (outError != NULL)) {
       *outError = [NSError errorWithDomain:NSOSStatusErrorDomain
                                       code:unimpErr userInfo:NULL];
    }

    return data;
}
----------------------------------------------------------------------

With the above mentioned test data it takes more than 5 minutes on my MBP 2.5GHz for finishEncoding to complete.

I've experimented and found the following:

1) When I change the values of v1, v2, v3, v4 to 1.0, 2.0, 3.0 and 4.0 everything works with acceptable speed (the process takes less than 5 seconds). It's still saving the same hierarchy, just the numbers stored are different. How can that be?

2) I also noticed that when I use the NSPropertyListXMLFormat_v1_0 instead of binary, the process speeds up considerably, taking just below 10 seconds. The problem with this is that the output file is huge (100 MB) which is too big for my purposes. Also, decoding the XML data is much slower than with binary data.

3) I've tried converting the doubles to strings and encode those. This also is a lot faster, almost as fast a with "straight" double values.

I've found nothing on Google or the list archives with respect to performance of NSArchiver and I'm puzzled. Also instruments isn't telling me much except that "flattenProperties" (if I recall correctly) is what most of the time is going.

What am I doing wrong? Thanks for any pointers!

Regards
Markus
--
__________________________________________
Markus Spoettl

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to