The best way to save object graphics on iPhone

I have an object graph in Objective-C on the iPhone platform that I want to save in order to blink when the application closes. The graph has about 100k-200k objects and contains many cycles (by design). I need to be able to read / write this chart as quickly as possible.

So far, I have been trying to use NSCoder. This not only fights with loops, but also requires age and a significant amount of memory to save the schedule - possibly because an XML document is used under the covers. I also used the SQLite database, but after going through this, many rows also take up a considerable amount of time.

I reviewed the use of Core-Data, but I'm afraid that I will have the same problems as SQLite or NSCoder, since I believe that the backup storage for the main data will work the same way.

So, is there any other way that I can handle the persistence of this graph of objects in a lite form - ideally, I would like something like serializing Java? I was thinking of trying Tokyo Cabinet or writing the memory used to link C structures to disk - but that would be a lot of rewriting.

+4
source share
2 answers

I would recommend rewriting as c structs. I know that it will be a pain, but it will not only write to disk quickly, but also work much better.

Before anyone gets upset, I'm not saying that people should always use structures, but there are situations where it is really better for performance. Especially if you pre-allocate your memory in about 20k contiguous blocks at a time (with pointers to the block), instead of creating / allocating many small pieces in a repeating loop.

those. if your loop constantly selects objects, it slows down. If you have pre-allocated 1000 structures and just have an array of pointers (or one pointer), this will be a large value faster.

(I had situations where even my desktop was too slow, and it did not have enough memory to cope with the fact that millions of objects are created in a row)

+1
source

Instead of skating on my own, I highly recommend taking a look at Core Data. Basic data have been developed from the ground up for the remaining graphs of objects . NSCoder-based archives, like the one you describe, require that you have the entire graphic in memory, and all records are atomic. Core Data brings objects to and from memory as needed and can only write part of your graph that has been changed to disk (via SQLite).

If you read the Master Data Programming Guide or their tutorial guide , you can see that they have been thinking a lot about performance optimization. If you follow Apple's recommendations (which may seem contradictory, as well as their assumption of denormalizing your data structures at some points), you can squeeze a lot more performance out of your data model than you expected. I have seen tests in which Core Data has successfully used manual SQLite to access data in databases whose size you are looking for.

On the iPhone, you also have some memory advantages when using batch size control for fetching and a very nice helper class in NSFetchedResultsController.

It does not take so long to create a realistic implementation of key data based on the principle of evidence of your schedule in order to compare it with existing methods of data storage.

+1
source

All Articles