Pedro Oliveira
Pedro Oliveira

Reputation: 20500

Android: Load database to memory vs queries over time

I'm working on a program that requires metadata information in order to populate some arrays. Let's say I have information like "Countries", "Districts" and a bunch of other metadata. That information is stored in a sqlite database. The program at some time need to load all the countries and iterate them in order to search for one. My question is: What is the best way to proceed: Keep the metadata in an array after query them, or every time I need them I should query the database?

Here's some more information so you can evaluate the performance: Metadata tables (like countries): ~10 Estimated times I need to iterate the metadata: several (~100) the arrays contains aprox. 5 fields (primitive types.)

Upvotes: 3

Views: 772

Answers (1)

CL.
CL.

Reputation: 180060

  1. If the amount of data is so large that if affects the amount of data available for your other data or for other app, you should keep it in the database and access it dynamically.
  2. If the amount of data is rather small, and it's queried rather often, keeping it in memory is more efficient.
  3. If the amount of data is rather small, and it's queried not very often, it will not make any noticeable difference what you do.

Your particular case is one of these three, but the only way to find out is to measure the performance yourself.

Upvotes: 4

Related Questions