Solved Whats better performance wise?

Discussion in 'Plugin Development' started by Sabersamus, Feb 13, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Sabersamus

    So, I have a server with 3Gb of ram, running only my plugin.
    But I feel that my plugin may take up too many resources, so

    Is it better to load a list on startup, as such:

    Code:java
    1.  
    2. private List<Zone> zones;
    3.  
    4. onEnable(){
    5. zones = Database.loadZones();
    6. }



    and then, change or add zones when needed, OR

    when a zone is needed, such as when a player enters or exits the zone, or builds in it,

    load the zone from the database directly?


    The way I see it, if I have a ton of zones, the list will be huge and it would take up resources, however the latter would execute a query to the database hundreds of times with players building. I don't know which to use.
     
  2. Offline

    Tirelessly

    Sabersamus The first one will almost always be better. You could test both methods yourself, though, and see how it goes.
     
  3. Offline

    Maurdekye

    Sabersamus Even if you think the first one will be slower to load all those zones, it will be much faster for the remainder of the server. If you think it might lockup your server, even if just for a second, you can attach it to a second thread. It's always better to deal with possible overhead in advance instead of calculating on-demand.
     
  4. Offline

    Sabersamus


    What do you mean attach it to a second thread?


    Currently the way I do it is the list, and then when I want a specific zone (by location) i use this:

    Code:java
    1.  
    2. public Zone getZoneAt(World world, Point p)
    3. {
    4. for(Zone zone: getZones(world.getName())){
    5. if(zone.contains(p)){
    6. return zone;
    7. }
    8. }
    9. return null;
    10. }
    11.  


    when a zone is created i register it in the database, and then add the zone to the list.
     
  5. Offline

    Maurdekye

    Sabersamus Forget about threads, they're unimportant. Just do it on startup.
     
  6. Offline

    Sabersamus


    Lol :p That's how I do it already.

    So, the way I do it now, is better for performance?
     
  7. Offline

    Maurdekye

    Sabersamus If you have a ridiculously large amount of zones needed to be loaded up, then it might be a bit slow at first, but it's always better.
     
    Sabersamus likes this.
  8. Offline

    Sabersamus


    Thank you!
     
Thread Status:
Not open for further replies.

Share This Page