objective c - iOS Realm - CPU Overload and block UI when save data -


i have 1 app use realm save data @ device. when need save big list (9k object), app blocking ui , cpu got 130% more 10minutes. tried set save method main thread ui still blocking. can help? want transaction don't block ui , need in background.

this method use save objects realm db. receive list of participantes , check before save if object exists in db.

dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{     (participante *p in participantes) {         participante *dbparticipante = [weakself fetchparticipantebyid:p.identification];         if(dbparticipante) {             [dbparticipante setidingresso:p.idingresso];             [dbparticipante setidentification:p.identification];             [dbparticipante setidcortesia:p.idcortesia];             [dbparticipante setidevento:p.idevento];             [dbparticipante setnome:p.nome];             [dbparticipante setdocumentonumero:p.documentonumero];             [dbparticipante setcodigoingresso:p.codigoingresso];             [dbparticipante settipoingresso:p.tipoingresso];             [dbparticipante save];         } else {             [p setsync:yes];             [p save];         }     } }); 

this method use save:

- (void)saveparticipante:(participante *)participante { [self writetransactionwithwriteblock:^(ysrealmwritetransaction *transaction, rlmrealm *realm) {     participanterealm *realmobject = [[participanterealm alloc] initwithmantlemodel:participante];     [realm addorupdateobject:realmobject]; }]; }  - (void)writetransactionwithwriteblock:(transactionwriteblock)writeblock {     rlmrealm *realm = [self realm];     [realm beginwritetransaction];      if (writeblock) writeblock(self, realm);      if (self.iscancelled) {         [realm cancelwritetransaction];     } else {         [realm commitwritetransaction];     } } 

i changed method save persist object in same transaction still blocking ui. cpu has obtain small improvement: 90%

- (void)saveparticipante3:(nsmutablearray *)participantelist { [self writetransactionwithwriteblock:^(ysrealmwritetransaction *transaction, rlmrealm *realm) {     (participante *p in participantelist) {         participanterealm *realmobject = [[participanterealm alloc] initwithmantlemodel:p];         [realm addorupdateobject:realmobject];     } } completion:^(ysrealmstore *store, ysrealmwritetransaction *transaction, rlmrealm *realm) {  }]; 

}


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -