[Solved] Delay upon Startup

Discussion in 'Spigot Plugin Development' started by HeadGam3z, Jun 26, 2015.

  1. I've noticed there is a little bit of a delay with a plugin of mine when it enables itself, and I'm not too sure as of why there's a delay. I have been in the process of re-coding the plugin to improve efficiency, but even now I'm getting a 1-2 second delay while it's enabling - and not even 50% of the code from the old version is added to the new one yet.

    Have you guys experienced delays when your plugins startup? If so, what caused they and what did you do to resolve the issue?

  2. Are you doing something like loading data from a file during startup? This can cause some lag when the plugin is enabled. Especially if you have a lot of data, adds quite a bit of time to enabling the plugin.
  3. I do load data, but not while the plugin startups - assuming all startup operations execute in the onEnable method. The data loads when it's called, say when a listener or command calls for it.
  4. What exactly are you doing when the plugin is enabled?
  5. Registering one event.
  6. Doesn't sound like that would cause any lag, what are you doing in that event class's constructor?
    1. Creating an instance of my ConfigFile class - already tried removing it, didn't remove nor reduce the delay.
    2. Assigning values to strings.
    3. Creating an inventory.
    4. Creating item stacks.
  7. It could possibly be my ConfigFile class - it loads, gets, and saves a lot of data. Plus I create a new instance of it every time I want to access some data from it in a method instead passing an instance of my main class to the class where I would need to use the built in getConfig() method...

    Has anyone experienced lag when creating their own custom file instead of using the built in getConfig() method?
  8. How much RAM is allocated to your server?
  9. Maybe its your computer lagging?
  10. 6GB.
    It's... possible. However, it's odd how it seems to always freeze up when it's my plugins turn to load.

    I have made some changes, though. I only have one instance for my ConfigFile class instead of multiple instances, and that has seemed to increase in-game performance by a lot. But I am still having a 1-2 second delay when the plugin starts up. :c
  11. Can you send the onEnable code?
  12. There's literally nothing that would decrease performance.

    Code (Text):
         * Actions to be performed when plugin starts up.
         * @author Jesse McCullough (HeadGam3z)
        public void onEnable() {
            getServer().getPluginManager().registerEvents(new ClassNameGoesHere(), this);
  13. Can you send your event class :p
  14. Replace ClassNameGoesHere with PickerListener.
    Code (Text):
    package com.headgam3z.easycolorchat.listeners;

    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.ItemStack;

    import com.headgam3z.easycolorchat.ColorType;
    import com.headgam3z.easycolorchat.PickerCreator;
    import com.headgam3z.easycolorchat.Utils;

    public class PickerListener implements Listener {
        public void onPickerListener(InventoryClickEvent e) {
            String invName = Utils.strip(e.getInventory().getName());
            String ccp = "Chat " + Utils.getC() + " Picker"; // chat colo(u)r picker
            if (!invName.equals(ccp)) {
            if (e.getCurrentItem() == null) {
            ItemStack picker = e.getCurrentItem();
            if (!picker.hasItemMeta()) {
            String pickerName = Utils.strip(picker.getItemMeta().getDisplayName());
            Player player = (Player) e.getWhoClicked();
            if (pickerName.equals("Dark Red " + ccp)) {
                PickerCreator darkRed = new PickerCreator(ColorType.DARK_RED, player);
            } else if (pickerName.equals("Light Red " + ccp)) {
                PickerCreator lightRed = new PickerCreator(ColorType.LIGHT_RED, player);
            } else if (pickerName.equals("Gold " + ccp)) {
                PickerCreator gold = new PickerCreator(ColorType.GOLD, player);
            } else if (pickerName.equals("Yellow " + ccp)) {
                PickerCreator yellow = new PickerCreator(ColorType.YELLOW, player);
             } else if (pickerName.equals("Dark Green " + ccp)) {
                 PickerCreator darkGreen = new PickerCreator(ColorType.DARK_GREEN, player);
             } else if (pickerName.equals("Light Green " + ccp)) {
                 PickerCreator lightGreen = new PickerCreator(ColorType.LIGHT_GREEN, player);
             } else if (pickerName.equals("Light Blue " + ccp)) {
                 PickerCreator lightBlue = new PickerCreator(ColorType.LIGHT_BLUE, player);
             } else if (pickerName.equals("Aqua " + ccp)) {
                 PickerCreator aqua = new PickerCreator(ColorType.AQUA, player);
             } else if (pickerName.equals("Dark Blue " + ccp)) {
                 PickerCreator darkBlue = new PickerCreator(ColorType.DARK_BLUE, player);
             } else if (pickerName.equals("Indigo " + ccp)) {
                 PickerCreator indigo = new PickerCreator(ColorType.INDIGO, player);
             } else if (pickerName.equals("Pink " + ccp)) {
                 PickerCreator pink = new PickerCreator(ColorType.PINK, player);
             } else if (pickerName.equals("Purple " + ccp)) {
                 PickerCreator purple = new PickerCreator(ColorType.PURPLE, player);
             } else if (pickerName.equals("White " + ccp)) {
                 PickerCreator white = new PickerCreator(ColorType.WHITE, player);
             } else if (pickerName.equals("Light Gray " + ccp)) {
                 PickerCreator lightGray = new PickerCreator(ColorType.LIGHT_GRAY, player);
             } else if (pickerName.equals("Dark Gray " + ccp)) {
                 PickerCreator darkGray = new PickerCreator(ColorType.DARK_GRAY, player);
             } else if (pickerName.equals("Black " + ccp)) {
                 PickerCreator black = new PickerCreator(ColorType.BLACK, player);
             } // TO DO RESET else if (pickerName.equals("Reset " + ccp))
  15. I have no idea why it's lagging, could just be a coincindence
  16. It's not occurring just once, though. It's every time I startup my server.
  17. After three days, 14 hours, and 52 minutes, I have determined the answer to my question.

    If your plugin.yml is extremely documented to the point where you have 6,314 lines of yml text like mine, your plugin will freeze up a little bit because it has to read that long, long, long file upon startup. Silly me.
    #18 HeadGam3z, Jun 27, 2015
    Last edited: Jun 27, 2015
    • Funny Funny x 1