B4J Question Performance Comparison: kvs v local map v local variables

GuyBooth

Active Member
Licensed User
Longtime User
I have a choice to make:
Do I access a kvs value directly from code? for example where gkvsSettings is the keystore and gsExeFolder and gsPlayerExe are values stored in it:
B4X:
PathToMiniPlayerExe = File.Combine(gkvsSettings.Get("gsExeFolder"),gkvsSettings.Get("gsPlayerExe"))
OR
Do I dump the kvs to a local map and access the values in the local map from code? Same values and keystore as above, with mapSettings as a local map:
B4X:
    ' Set this up once
    Wait For(gkvsSettings.GetMapAsync(gkvsSettings.ListKeys)) complete (mapSettings As Map)
    ' Then access settings from local map like this:
    PathToMiniPlayerExe = File.Combine(mapSettings.Get("gsExeFolder"),mapSettings.Get("gsPlayerExe"))
OR
Do I dump the kvs values to local variables and access the local variables from code?
B4X:
    ' Set this up once for all the keys in the keystore:
    gsExeFolder = gkvsSettings.Get("ExeFolder")
    gsPlayerExe = gkvsSettings.Get("PlayerExe")
' etc for all the keys. Then
    PathToMiniPlayerExe = File.Combine(gsExeFolder, gsPlayerExe)
A performance hit to set up the different scenarios is not a problem.
My question is: Is there a big performance difference between these methods during extraction of the individual values?
 

GuyBooth

Active Member
Licensed User
Longtime User
There are possibly 20 different values. Many of them are used for selecting paths and song file names to load and play them.
Typically in a single task three or four individual values are only used once - a folder, a path, a filename for example. Such a task may be run once every three or four minutes.
Setting them up (if this is what you mean by preoptimization) need only be done once when the program is first started - but I would only need to do it the very first time the program is run, to load the kvs with values. If the performance hit by working directly with the kvs is minimal, that is the easiest way to code it.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…