Optimizing unresponsive (Core Data) app for OSX

142 Views Asked by At

having real problems with a very unresponsive (OSX) app. When using about 3K (Core Data) objects, the app freezes during startup and save, and when adding new managed objects.

When I dig into the call tree, using (Instruments) Time Profiler, most of the time seems to be spent sorting array controllers. During startup, half of the time goes to NSUndoManager, which observes notifications while array controllers are setting their content...

Is the array controller sorting while new managed objects are being instantiated? Do I need to put sorting on hold? Could NSUndoManager be the culprit?

More importantly, how does one go about analyzing something like this? It could very well be that I have some sort of exponential sorting going on, by which I mean that when one array controller sorts itself, several other array controllers may needlessly start re-sorting themselves too.

The datamodel I am using is fairly extensive. Also, I have about 30-ish array controllers in 2 .xib files, some of them managing the same class-type.

Marcus Zarra's book on Core Data has been very informative, in this context especially the chapter on optimizing Core Data.

Also, this article by Matt Gallagher is pretty impressive, although the issue I'm having probably isn't related to code that needs to be optimized.

Any and all tips are welcome, I am pulling my hair out here. Could you point me to some tutorials or books that could help me out? Thanks.

1

There are 1 best solutions below

1
On

If half the time is being taken by undoManager, but you see no performance improvement when removing the undo manager, I'd say you should look at IO as your potential bottleneck.

Look at the amount of time spent doing I/O operations.

Also, when it comes to core data, I'd do all my work in a background thread. No sense letting it hang your UI. Hopefully, you are able to use parent/child MOCs, as that greatly simplifies working with multiple contexts.

Even if it does not, it's worth the extra work to get it working in a separate thread. Your UI will thank you.