Android Question KeyValueStore - performance?

GuyBooth

Active Member
Licensed User
Longtime User
I have a value that is already stored in a KeyValueStore.
I am setting up a loop that needs to read this value once or twice each time the loop is executed.
Is there a performance - or other - penalty to "getting" it from the KeyValueStore each time? Versus "getting" it and storing it in a private variable before the loop starts, and reading the variable each time the loop executes?
If KeyValueStores were stored on a hard drive, the answer would be obvious, but phone memory is different.
Would appreciate it if anyone has an answer.
 

Roycefer

Well-Known Member
Licensed User
Longtime User
It will be a lot faster to store the value in a variable rather than reading it from the KeyValueStore each time. The KeyValueStore is stored on the device's SD card or internal flash storage whereas variables are stored in RAM. RAM is much faster. However, whether or not you will notice the performance difference depends on the details of your program. But there is no advantage to reading it from the KeyValueStore each time.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
I do it on my own with list(s) and maps added to it/them. I store it as a file and read the list once at the start (with all the maps containig the data). It can be easily expanded just by adding new maps. Very easy and fast. If you need many parameters all the time then just use ONE map with unique keys. You can access it very fast.
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
Note that you should use KeyValueStore2. It is faster than KeyValueStore 1.

That's the one I'm using.
My app is small, but the code directly accessing the KeyValueStore is so much simpler (as well in my app it is vital that these variables are not lost if the phone is switched off, cleanly or otherwise). So for this one I'll use the KeyValueStore as variables.
Thanks everyone for your input.
 
Upvote 0
Top