title: CoreData optimization for big data
body: <p>The fetching request inside the block taking around 9 minutes to process checked on instrument customerArray has around 60K objects and    CusCustomerAddress Model has around 30k objects so I have to optimise this time.</p>
  
  <pre><code>   NSArray *customerArray=[engine getItemsForEntity:@"CusCustomer" predicate:nil error:nil];
          NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"id1 == $idVar"]];
          NSPredicate *predicateCustomerAddress = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"customerId == $customerIdVar AND addressType == $addressTypeVar"]];
  
      [customerArray enumerateObjectsUsingBlock:^(CusCustomer *customer, NSUInteger idx, BOOL *stop) {            
          NSString *customerId=customer.id1;
          NSString *addressType = ShippingAddress;
          NSDictionary *variablesAddress = @{ @"customerIdVar" : customerId , @"addressTypeVar" : addressType};
          NSArray *resultAddress = [engine getItemsForEntity:@"CusCustomerAddress" predicate:[predicateCustomerAddress        predicateWithSubstitutionVariables:variablesAddress] error:nil];
          if (resultAddress.count == 1 ) {
              [customer addCustomerAddressObject:(CusCustomerAddress *)[resultAddress lastObject]];
          }
          else
          {
              DLogHp(@"More than one tuple Exist For  this'id1' =\"%@\" in \"CusCustomerGroup\"",objId);
          }
          addressType = BillingAddress;
          NSDictionary *variablesAddress1 = @{ @"customerIdVar" : customerId , @"addressTypeVar" : addressType};
  
          NSArray *resultaddress1 = [engine getItemsForEntity:@"CusCustomerAddress" predicate:[predicateCustomerAddress predicateWithSubstitutionVariables:variablesAddress1] error:nil];
  
          if (resultaddress1.count == 1 ) {
              [customer addCustomerAddressObject:(CusCustomerAddress *)[resultaddress1 lastObject]];
          }
          else
          {
              DLogHp(@"More than one tuple Exist For  this'id1' =\"%@\" in \"CusCustomerGroup\"",objId);
          }
      }];
  
  }
  </code></pre>