PDA

View Full Version : archiveRootObject takes VERY long




Till Roenneberg
Sep 11, 2008, 05:51 AM
In my Cocoa application (not document based), I write a key-coded array to the disc and the method works perfectly. The only drawback is that it takes ages (OS 10.4.1). Granted, the file is 6 MB but should it really take several minutes? Any suggestions why this is so slow and how to make it faster?

Thanks,
Till


NSMutableDictionary *rootObject = [NSMutableDictionary dictionary];
[rootObject setValue: [here, I pass an NSMUtableArray created in the program]
forKey:@"channels"];
[NSKeyedArchiver archiveRootObject: rootObject toFile: path];



Sayer
Sep 11, 2008, 07:52 AM
Build a debug version and run and attach Shark to it to see where its spending so much time.

And, well, a 6 meg mutable array? Geeze. Write a custom data storage class or something. Ask Google, there's all kinds of stuff out there.

Till Roenneberg
Sep 12, 2008, 04:18 AM
Thanks. I am new to Cocoa and I still have to learn a lot before writing a custom data storage class (BTW, I couldn't find anything obviously useful in Google under these key words).

I just realised that if I compile for powerPC, the save process is very fast but when I compile for intel, it becomes unbearably slow.
Any idea why?

JonnyThunder
Sep 12, 2008, 05:33 AM
I know that iPhone has SQLite ability built in, which would be perfect for this type of application - but I'm too new at Obj-C to know whether it's part of Cocoa or not. (if not, i'm sure you can find a library for it somewhere)

robbieduncan
Sep 12, 2008, 05:52 AM
What sort of data are you saving? At 6Mb in size I am assuming it's binary data, not text. Images? Audio? Have you looked at using a package filetype instead (basically a directory that acts as a file). This is how Pages etc saves it's data. The advantage of this is that you can save the data in it's native format which should be quicker.

Till Roenneberg
Sep 12, 2008, 08:02 AM
I am saving channels of experiments. They are custom classes that can hold a variety of data, times and values of time series, channel descriptions as text. Since I am displaying the channels and their content in a lot of windows, they have property lists so that they can easily be updated in tables. The files are dynamic, so that more channels can be added, more information can be added to existing channels (data types which are another custom class with properties). In future, there may be an extension to saving graphs with the channels but presently, it's only Arrays, Strings, and Properties.

Thanks Till

robbieduncan
Sep 12, 2008, 08:05 AM
In that case it sounds like something in your code is causing the archiver to run very slowly for some reason. The above suggestion to profile in Shark is the best way forward: find out what the code is spending it's time doing and then try and fix that...