Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8172613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:50:30+00:00 2026-06-06T21:50:30+00:00

I was curious if there was a performance gain from creating a Fetch Request

  • 0

I was curious if there was a performance gain from creating a Fetch Request Template versus programmatically creating NSFetchRequest so I wrote some tests to measure this. Here’s the source on github.

Same order of difference in Simulator and on iPhone (measuring time interval to do a bunch of fetches):

just creating an NSFetchRequest:          4.399674
creating a Fetch Request Template:        0.501369
NSFetchRequest with field indexed:        0.407068
Fetch Request Template and field indexed: 0.281876

It turns out there’s about 7~9 times performance gain in creating a Fetch Request Template. I thought maybe it’s creating the proper index underneath but when I created an Fetch Request Template that matches on an indexed field, there’s even a further performance benefit.

Ok, nice to know that this is the case, but I would very much like to know what the heck is happening underneath the Fetch Request Template that accounts for performance gains?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:50:32+00:00Added an answer on June 6, 2026 at 9:50 pm

    Update

    After some profiling with Instruments, it turns out [NSPredicate predicateWithFormat:] is not the culprit here!

    The actual cause of the performance difference is sort descriptors.

    The non-template tests are using an NSFetchedResultsController, which requires a sort descriptor, whereas the template-based ones do not specify a sort descriptor.

    If you add a sort descriptor to all the tests, the performance evens out (with the exception of the indexed case.)


    Original (wrong) answer

    The performance penalty is because your ‘just creating a NSFetchRequest’ test calls [NSPredicate predicateWithFormat:] for each iteration of the loop – this is very slow!

    Think about it – [NSPredicate predicateWithFormat:] has to parse the string and basically compile it into the internal representation used by Core Data.

    The usual solution is to only call [NSPredicate predicateWithFormat:] once, and then use [NSPredicate predicateWithSubstitutionVariables:] to specify the values that will be compared by the predicate – this is covered in the Core Data Documentation – Efficiently Importing Data

    To create a predicate from a formatted string, the framework must
    parse the string and create instances of predicate and expression
    objects. If you are using the same form of a predicate many times over
    but changing the value of one of the constant value expressions on
    each use, it is more efficient to create a predicate once and then use
    variable substitution (see “Creating Predicates”).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am curious, is there any performance gain, like using less memory or resources
I am curious if there is a way from within a WebView when a
Just curious why there is a performance enhancement when you standardize a site with
I'm just curious: Is there a difference on speed and performance between this two
Just curious if there is anyway to display an objects retain count using NSLog.
I'm curious if there is an efficient way to wait for the front page
I'm just curious if there's a reason why in order to represent -1 in
I’m curious if there is standard or guideline for determining what types of things
I am just curious if there is a way to swap the two stings
I am curious if there is a way where I can capture the lower

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.