4

I have an array with around 200K elements and I am using this predicate to filter some elements.

NSArray * filteredArray = [mainArray filteredArrayUsingPredicate: 
  [NSPredicate predicateWithFormat: @"(value1 == %@) && 
  (value2 == %@) && (value3 >= %d) && (value4 != %@)",
  value1, value2, value3, value4]
];

When I am running this app in iPad older iOS versions this code takes 0.22 seconds for execution. (I have tested in iOS 14.7, 12.4, 13.2 etc..). But when I am running the it in iOS 15.1 or 15.2 the same code takes 0.63 seconds for execution.

Does anyone know why it is taking long time in new iOS version? Any help would be appreciated.

Sulthan
  • 128,090
  • 22
  • 218
  • 270
  • For clarity, the formatting is a little off so could you change it so we know how many elements you mean. 200K or 2M or...? – Joakim Danielson Jan 09 '22 at 11:54
  • Did you test this on a simulator or on a real device? – koen Jan 09 '22 at 14:16
  • What does the time profiler in Instruments have to say about the difference? – Warren Burton Jan 09 '22 at 14:18
  • Did your test use a Release build that optimized for speed? And please show your test harness code; don't make us guess how you're testing. – matt Jan 09 '22 at 14:26
  • Are the iPad model the same? For instance, if you are doing high CPU calculations elsewhere that could change because of the resolutions of the screen, it could affect it. – Larme Jan 10 '22 at 09:10
  • @Larme I have tested the same in my new iPad Air with iOS 14.7 and then I updated iOS 15.5 and tested. I am getting the delay in iOS 15.2 – Mohammed Abdul Basith Jan 10 '22 at 11:44
  • @matt I have tried in release build, it makes some inpremvents in both older and newer iOS versions. But still iOS 15.2 takes almost 3-4 times higher time. – Mohammed Abdul Basith Jan 10 '22 at 11:45
  • @koen I have tested the same in real device and simulators. I am seeing this issue in both. – Mohammed Abdul Basith Jan 10 '22 at 11:46
  • @WarrenBurton The code which I uses is a small part of a complex and large algorithm. I am not able to profile for this. Profiles goes upto 50 gb and finally it crashes. A time difference of just 0.4 seconds makes a 45 second delay in my total calculations. – Mohammed Abdul Basith Jan 10 '22 at 11:50
  • A couple of suggestions. Profile with a small subset of records to try and discover the difference and rewrite the search fragment in Swift to see if there is some form of Foundation bridging which is bogging the search. – Warren Burton Jan 12 '22 at 13:38
  • Do you intentionally have two comparisons for `value1` or is that a typo? – de. Jan 13 '22 at 11:23
  • @de. Sorry. It was a typo – Mohammed Abdul Basith Jan 14 '22 at 13:41
  • 1
    Adding a bounty does not magically improve the question. It just throws away rep unless the question is improved to make the "issue" reproducible by others. – matt Jan 14 '22 at 13:49

0 Answers0