-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a reason the managedObjectModel is re-created for each BSManagedDocument instance? #33
Comments
I've followed Apple's lead an made this an instance method. On that basis, I was a bit wary of doing any extra caching beyond whatever Apple might be doing behind the scenes. I don't know if Apple have a particularly good reason for this setup, but they certainly seem keen on it, having used it again for I suppose theoretically an app could be modifying the model before it's used for the first time, and that modification is per-document, but that does seem pretty unlikely! All that said, are you actually finding this to be slow, or just speculating? It's nice and easy in your app to override |
I just like efficiency, and low memory footprint in any NS or UI App I’m doing. I was expecting an “Infrastructure” class like BSManagedDocument to try to be efficient. If you tell me that NSManagedDocument and UIManagedDocument keep distinct models for each document - I’ll agree that this is the way to go in a replacement class like BSManagedDocument. However, my question still stands: Could multiple CoreData stacks (for multiple open documents) share the same instance of the model for setup? Won’t Core-Data get angry?
|
Well you haven't proven that we're being inefficient here. Counter-deal: you show me that If one were to be pedantic, caching the model isn't necessarily a magical efficiency win:
My answer still stands:
|
However keep in mind that all of this is premature optimization – how big your models are anyway and on top of that the Mac has a page file (unlike iOS) hence it may not worth the extra effort and complexity to cache this.
|
Yes, it works just fine to share the same instance of the model |
Well, the first to say "cache" was you... I never meant "caching" the model, but rather making it a "class property". First document will create the model, every document will retain it, the last document to be released, will release the model --- a simple old-style shared object. Then, it is quite simple to see what NSDocument does. Just create 2 documents, and in the debugger crawl up the model stack until you see the addresses of the models of those documents. Are they the same object? Same method to see if UIManagedDocument does this too. I'll test and tell you my results as soon as I can. On 3 בדצמ 2014, at 19:12, Mike Abdullah [email protected] wrote:
Motti Shneor mobile: +972-54-3136621Ceterum censeo Microsoftinem delendam esse |
An NSManagedObjectModel is not very "lightweight" and it also is exactly the same for all the instances of a BSManagedDocument (or per specific subclass).
Question is: why not share the model for all open documents? If my app regularly keeps 5-6 documents open, and my model is pretty big (some 20 entities with many validation rules, relations etc) wouldn't it be wiser to have just one model ?
Or is it somehow cached behind the scenes by CoreData itself, when you [NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObject:[NSBundle mainBundle]]] every time?
The text was updated successfully, but these errors were encountered: