Which is Better for Loading Data?

Discussion in 'Spigot Plugin Development' started by Futurize, May 6, 2017.

  1. Which is better for loading player data? Currently, I save the data to the config file and then retrieve it using getConfig().getString(name) whenever they use a command. Would it be better to use a HashMap and then just save it to config on restarts and reload it back on onEnable()? Any help would be appreciated.
  2. just save them on config or database , don't make it too hard =='
    #2 mkcoldwolf, May 6, 2017
    Last edited: May 6, 2017
  3. It really depends how often you load the data, and how much data you have. If you have hundreds, thousands, or more data, you would need to use a database like SQLite. If it is just some light configuration stuff or very little data for storing like a player's status on something, usually you can get away with using a custom config or the default config.
  4. Personally, I think if you don't have to make the data jump between different servers, you should use files.
    Else use a database :p
  5. If you have a large amount of data, files can be very slow and inefficient.
  6. Photon


    Depending on how often you call those methods you should use some intelligent caching.
    If you call the method every tick for every user you should definitely have them in memory, if possible with no recursive algorithm.
    Generally it is good to create a OOP system to handle your players e.g. in a "User" class for fast access.
    File streams (getConfig()) are a huge performance issue in general, only use them when you really need them / async or when you do not must have good performance.
  7. Yes but with just one server, you don't have enough data to see the difference.
  8. Personally, I like to get all the data I need from a file once asynchronously and only update/save any files asynchronously when I need too (Player logging out e.c.t). Depending on how much data we are talking about, you might not see any real performance increase. Although keeping things optimal is nice :)
    • Agree Agree x 1
  9. Thanks for the help. Also, how can I loop through every config file in a folder to retrieve something in each of them?
  10. Photon


    Take a look at the java file system. The oracle docs will help you for sure.