[PERFORMANCE] 1 Class for all Commands vs A Class for every Command

Discussion in 'Plugin Development' started by KollegahDerBoss, Feb 20, 2013.

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

    KollegahDerBoss

    I was wondering:
    -------------------------------------------------

    What is actually faster and less RAM taking, all Commands in one Class, or for every Command one Class?
    I know we are talking about Milliseconds of Speed here, still it's an interesting Question.


    -------------------------------------------------
    When you do all Commands in one Class, you have to do several If-Checks of how the Command is called. In This way, the RAM is only using up 1 Class, but the CPU is a bit under pressure.

    However, doing for every Command one Class, should be faster, since you are setting the Executor for that Command to a particular Class, in this way it's faster. But what about the RAM? Opening 50 different Classes for 50 different Commands, wouldn't that be a bit too much?

    -------------------------------------------------

    I've been struggling about this Question some time, but I haven't found a Thread or Website talking about this. What is actually worth using?

    -------------------------------------------------

    I would love to hear about your thoughts.
     
  2. hmm...
    les ram: all in one
    faster: all in seperate
     
  3. Offline

    Jozeth

    If you have lots of commands just have separate classes for them, it's easier to edit (I know you could put comments in to do Ctrl+F). But if it's just 5 commands or less just put them in one.

    I put in them in separate classes.
    Most servers have powerful CPUs but some people only by 1GB of RAM or less.
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    If you really want to measure the kilobytes from the extra pointers and sacrifice code maintainability, that is always the wrong decision.
     
    zeeveener and tehbeard like this.
  5. Offline

    iBawb

    I'm just thinking, would it be possible to create a method within each seperate class for each command, then setting the commandLabel to lower case and then running commandLabel.method(), then if there is no class with that name, do nothing. If that's possible to perform, would it be more or less efficient that the typical methods we currently use?
     
  6. Offline

    KollegahDerBoss

    I don't care about the Code Maintainability, I've used all Commands in one for now (about 60), but I wanted to switch to 'Class for every Command'. Is it performance advantaged or not?
     
  7. Offline

    RealDope

    You will notice no performance difference with this, as you said, we're talking milliseconds, which will not be noticeable.

    You WILL on the other hand, notice a large difference in your and other developers' ability to read and edit your code.
     
  8. Offline

    Sagacious_Zed Bukkit Docs

    If you look at how bukkit works, it maps a string to a command executor class which is executed for that command.

    For a large number of commands, having classes for each command is generally a good idea
     
  9. Offline

    Deleted user

    Can I see an example of how to do this?
     
  10. Offline

    Deleted user

    Right except a CommandExecutor is basically still all the commands in once class. I want a class per command, I know I'll need to create a "Command" class and all applicable classes need to implement it I just, idk I'm a bit confused and if someone could explain it to me I'd really appreciate it.
     
  11. Offline

    ZeusAllMighty11

    No... it's not. I thought you were a professional developer T__T



    Anyways, when a class impelements commandexecutor it just means that it handles command execution, simple enough.

    So in our plugin.yml we have command "test". In the main class, we have
    getCommand("test").setExecutor(new CommandClass());
    which means that the command /test from the CommandClass class will be executed, so you don't have to do a check if(cmd.getName().blah blah);



    having a class implement CommandExecutor is not all commands in one class ... /facepalm lol
     
  12. Eballer48
    Apparently you are confused, that example is for one command to trigger one class... the key is:
    Code:
    getCommand("basic").setExecutor(new MyPluginCommandExecutor(this));
    You set diferent classes to diferent commands, simple.

    EDIT: This forum should really temporary prevent replying if someone else posted while you were typing and notify you of that...
     
  13. Offline

    Deleted user

    Hehe trolling is fun, I'm just messing with y'all.
     
  14. Offline

    ZeusAllMighty11

  15. Good to know, I'll just avoid your posts from now on :)
     
    ZeusAllMighty11 likes this.
  16. Offline

    Deleted user

    Can you write me a PHP script to check when the PlayerMoveEvent is fired?
     
  17. Offline

    RealDope

    Not seeing what that has to do with fail trolling?..
     
    ZeusAllMighty11 likes this.
  18. Offline

    Deleted user

  19. Offline

    Mango

    The performance difference is nanoseconds at most. Do whatever you're more comfortable with. It doesn't really matter that much. Also, I have to say that Mineblemone has absolutely no idea what he's talking about.
     
    RealDope likes this.
  20. Offline

    ohtwo

    Claim you're trolling when you were actually serious to cover up ignorance?
     
    ZeusAllMighty11 likes this.
  21. Offline

    zeeveener

    As someone who reads alot of code, it is alot NICER to have them separated by class. However, as everyone has already noted, there will be no noticeable difference performance-wise.
     
Thread Status:
Not open for further replies.

Share This Page