At the SF Parse Meetup earlier this month, I talked with some of you about tips for making your Parse app faster and more reliable. Here is a recap of that presentation.
At Parse, we are constantly improving our infrastructure to make your app scale auto-magically. Our platform load balances your traffic, elastically provisions your app’s backend resources, and backs up your data on redundant storage. On top of our MongoDB datastore, we built an API layer that seamlessly integrates with our client-side SDKs. Our cloud infrastructure uses online learning algorithms to automatically rewrite inefficient queries and generate database indexes based on your app’s realtime query stream.
You can further improve your app’s performance with a few more simple tips. (Some links here are for Android, but we have analogous docs for other platforms too.)
- Cache whenever you can. You can turn on client-side query caching using the
- Write restrictive queries. You should write queries that return only what the client actually needs. Returning a ton of unnecessary objects back to the client can make your app slower due to network traffic. Please review our Querying Guide to see whether you should add any constraints on your existing queries. You should also try to avoid non-restrictive query clauses such as
whereNotEqualTo. If you are issuing queries on GeoPoints, make sure you specify a reasonable radius. In addition, you can limit the object fields returned with
selectKeysso that the phone client doesn’t have to wait for large unrelated fields to download.
- Design your data model for efficient querying. Please check out our Relations Guide for details.
We also have a few recommendations for specific scenarios:
- Displaying counts on the UI. Suppose you are building a product catalog. You might want to display the count of products in each category on the top-level navigation screen. If you run a count query for each of these UI elements, they will not run efficiently on large data sets because MongoDB does not use counting B-trees. Instead, we recommend that you use a separate Parse Object to keep track of counts for each category. Whenever a product gets added or deleted, you can increment or decrement the counts in an afterSave or afterDelete Cloud Code handler.
- Text search. MongoDB is not efficient for doing partial string matching except for the special case where you only want a prefix match. For adding efficient text search to your app, please see our previous post.
We hope that these tips will help you build apps that are responsive and delightful to use. I also want to thank everyone who submitted feedback or questions because this talk was mainly based on the feedback from our wonderful developer community. So keep building awesome apps, and send us your thoughts!