cocoa - core data object insert in loop causes problems with NSNumber* property on object novel in inner-loop -


i have loop has degrading performance proceeds (the first loop might 3 seconds, last might 400 on 500 iterations). i've narrowed down 1 line of code . . . attaching unique nsnumber value core data object. catalog size typically 20k-150k.

here excerpt runs in outer loop. outer loop gets slower , slower each time due 1 line of code:

for(int = 0 ; < 500 ; i++){   nsstring *key = @"somerandomstring" ;    nsnumber* sampleidnumber = [nsnumber numberwithint:13] ;   (it = catalog.begin(); != catalog.end(); it++) {     // it->second->id changes each time in inner-loop     nsnumber* tagnumber = [nsnumber numberwithint:it->second->id];     datummo *newdatummo = [nsentitydescription insertnewobjectforentityforname:@"datum" inmanagedobjectcontext:moc];      // **tagnumber changes each inner loop**     // **each time outer loop calculated gets slower**     // **this not happen if tagnumber constant**     newdatummo.tagid = tagnumber ;      newdatummo.name = key;     newdatummo.sampleid = sampleidnumber;  } } 

a few other points: arc code, autoreleasepool defined around loop, doesn't make difference. 'tagid' , 'sampleid' both integer32 in core data datamodel.

what i've tried far: - redefine tagid int32_t (no change) - use stl map predefine nsnumber* , lookup (no change) - assign tagid constant (fixes problem, not right) - assign random int tagid (make worse, of course)

this seems close, unclear if actual problem or if best practice handling scalars in core-data.

http://blog.lorentey.hu/2010/10/31/core-data-scalars/

update 1 implemented scalar model described in above link no change in behavior. going run further instrumentation on it. cpu gets starved (is pegged initially) , memory constant, either swapping out / loading stuff memory more needs to, or writes core-data slowing down. adjusting core-data write frequency yields no difference in effect (though effects performance). removing autoreleasepool calls yields obvious effects in process. going try switching use nsstring* next i'm out of ideas.

duh, datummo.tagid indexed column (as sampleid). if i'm creating 100k unique, indexed inserts appears cause significant slow-down number of inserts goes (must doing linear scan somewhere?). not sure if provide sufficient speedup or need post-load indexing, custom or otherwise, question.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -