1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

What causes slow server performance with Skript?

Discussion in 'Skript' started by CactusMan42, Aug 16, 2019.

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

    CactusMan42 Member

    Joined:
    Aug 12, 2019
    Messages:
    3
    Likes Received:
    0
    Im not sure where to put this. When writing skripts what causes the server to lag / run slower? My server doesn't lag now, but just to know what to kind of avoid.
     
  2. malia

    malia Well-Known Member

    Joined:
    Jul 24, 2019
    Messages:
    314
    Likes Received:
    21
    Storing variables unecessarily, infinite loops, every second loops, unecessary loops, I would recommend you to learn just a bit of programming, trust me it's gonna be worth it, even on Skript. Personally I recommend C++ as it's one of the languages that require most performance adaptation.
     
    • Like Like x 1
  3. CactusMan42

    CactusMan42 Member

    Joined:
    Aug 12, 2019
    Messages:
    3
    Likes Received:
    0
    I already know some languages, but thanks for the quick reply. But I will definitely start learning some C++
     
  4. malia

    malia Well-Known Member

    Joined:
    Jul 24, 2019
    Messages:
    314
    Likes Received:
    21
    Great, good luck DM if help needed :emoji_slight_smile:
     
  5. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    225
    To add on to what Malia said, the #1 performance killer is periodical loops. Try to avoid them as much as possible, and if you do need to use them, use a reasonable time, here's an example of one I saw the other day that hurt my soul
    Code (Skript):
    1. every tick:
    2.     loop all players:
    3.         loop 20 times:
    4.             add 1 to health of loop-player
    Now, in this example, EVERY SINGLE TICK on the server, we are looping all players, then within that loop we are looping 20 times and adding to their health. What the person writing here didn't realize is all of this is attempting to happen in ONE TICK. Not to mention adding 1 to the player's health 20 times in one tick will have the same effect as just setting their health to max.
    Even that being said, let's say you have 20 players on your server, EACH TICK on the server you are attempting to loop all 20 players, and run more code for each player.
    Things like this will just eat up your performance, because during this same tick the server is trying to do hundreds of other tasks, but this one shitty script is trying to do hundreds of tasks as well.

    If you were really needing to do something like this, space your periodical loops out. Do some math and try to estimate the damage its going to do to your server, and think realistically, does a players health need to update every tick? GOD NO... plus theres game rules for things like this.

    Having a good understanding of programming as well as a good understanding of how MC works, can help you write scripts that actually perform very well on your server.
     
    • Agree Agree x 1
  6. malia

    malia Well-Known Member

    Joined:
    Jul 24, 2019
    Messages:
    314
    Likes Received:
    21
    You could also share your Skript code so people that are skilled in the area can analyze your code, and give you tips :emoji_slight_smile:
     
Thread Status:
Not open for further replies.

Share This Page

Loading...