Core Data hanging when editing NSTextView on a previously saved document

Discussion in 'Mac Programming' started by sylvantemplar, Nov 14, 2011.

  1. sylvantemplar macrumors newbie

    Nov 14, 2011
    Interesting problem here:

    I've got a handful of textviews connected to a Core Data model. Everything works fine, except one thing.

    When I put information into a textview, the entire application slows to a crawl, invoking the beachball.

    When I attached a Core Data Instrument to my app's process, NSManagedObjectContext save is being called with each character that is typed. This lag is crippling the entire application.

    To make things stranger, the problem is not consistent. Sometimes the app decides it needs to write to the saved document (SQLite, XML, binary, doesn't matter) for each and every character that is typed into the textview, and other times it won't.

    Any ideas?
  2. sylvantemplar thread starter macrumors newbie

    Nov 14, 2011
    Update: after poking around the document implementation file, I saw the class method autoSavesInPlace returning YES. I suspected that this might have something to do with it, and it turns out it did. Something about the managedContext does not like this method to return YES, and feels compelled to perform incremental saves at inappropriate times. Setting this method to return NO completely resolved my issue. It's worth noting that this method is defaulted to return YES, so if you ever find yourself having save performance issues, try setting it to NO.
  3. Kenndac macrumors 6502


    Jun 28, 2003
    Also, make sure the text fields aren't marked as "Continuous" in Interface Builder, otherwise they'll cause your behaviour.

Share This Page