0

I am a programming noob writing a relatively large application for Android using Java code. The app is basically a game in which each user has a team with multiple players. Up until this point I have been using saved instance state and class instance variables to save game progress / player stats, but now that the app is almost completely written I have foolishly only just decided to learn & incorporate an SQLite database so that a users progress can be saved and resumed even after exiting the app. [sigh]

My question is simply for someone to explain the pros and cons of the following please:

  1. updating each instance variable (and there are a lot of them) individually as the program runs. (I am just delving into learning about SQLite databases, but I gather the impression that constantly calling the cursor and writing/reading data from a database will be noticeably slower than how it ran originally with just instance variables and saved instance states) is this true?

  2. Find a convenient place to update the entirety of the database all at one time (Again this is a pretty decent sized app and i fear that maybe waiting to save everything to the database upon exit will present a very noticeable lag) am I wrong?

  3. Should I update the database at random periodic intervals? (would the best solution be to update all instance variables to the database every time a user changes activities (or something similar ) here-by lessening the database write time at least some so that when the database gets inevitably updated upon exit, it won't have as huge a lag time)

I would really like to have an idea of this before I basically have to overhaul my entire app to incorporate SQLite. I would much appreciate a suggestion on the best route to go. Thank you!

Azeem
  • 11,148
  • 4
  • 27
  • 40
Paris B. G.
  • 374
  • 1
  • 3
  • 14
  • 1
    With appropriate use of transactions and possibly other tuning, sqlite can handle tens of thousands of inserts a second. Updates of existing records would be slower, but probably not by much. [Detailed experiments](https://stackoverflow.com/questions/1711631/improve-insert-per-second-performance-of-sqlite?rq=1). What I would do is pick a logical place to start a transaction (Like the start of a turn), update the database as objects are modified (Using cached prepared statements instead of always recompiling each update), commit the transaction at a logical place like end of turn, and repeat. – Shawn Aug 31 '18 at 00:13
  • Hmm.. So basically I should update as each object is updated because, PERFORMANCE WISE, there is little to no difference between saving to SQLIte and saving to a java class instance variable? Ok! Thank you very much, and sorry for such a simple question. Time to start tackling this database stuff!! – Paris B. G. Aug 31 '18 at 00:36

0 Answers0