Jump to content

Script optimisations to reduce lag


Recommended Posts

Posted

I've noticed that the client lags considerably when running my script.
What measures can I take to ensure that my script consumes as little resources as possible?
I've increased the onLoop counter to reduce loops per minute and am also using a series of "else if" conditional statements instead of a series of "if" statements to reduce the number of conditions checked.

What else can I do?

Posted
7 minutes ago, Adept said:

I've noticed that the client lags considerably when running my script.
What measures can I take to ensure that my script consumes as little resources as possible?
I've increased the onLoop counter to reduce loops per minute and am also using a series of "else if" conditional statements instead of a series of "if" statements to reduce the number of conditions checked.

What else can I do?

It would be helpful if you showed us the source code so we can tell you where you are going wrong.

Also in the future please post in the Scripting Help section

  • Like 1
Posted

chances are that if your code is really laggy, using else ifs vs. ifs wont really help. you're probably doing an inefficient calculation or something that takes a ridiculous amount of time, either in your onLoop() or onPaint(). also check that you're not getting any exceptions

if you want specific help, you'll need to post your source code.

  • Like 1
Posted (edited)
41 minutes ago, Juggles said:

Don't use webWalk 

I think that the user means CPU usage, webWalking isn't very CPU intensive after it calculates the route. It does consume 200-300MB ram, but that is to be expected

First of all, I'd suggest to use ConditionalSleeps where applicable. Many beginning scripters tend to put their codebase into one giant loop with a lot of condition checking

A smarter way is to split up your script into 'Tasks' or 'States' paired with a getTask(), getState(), or similar.

When a task has been executed you conditionalsleep until a certain condition is met (or it times out). Using this method I can easily run 50 clients on a modern quad core CPU

Something along the lines of :

uiYWLdi.png

O35SViy.png

V3dRTzl.png

XWAKqxz.png

There are many ways to accomplish this, so don't limit yourself to my method. I generally write scripts in a rush :boge:

Edited by Abuse
  • Like 2
Posted
4 minutes ago, Abuse said:

I think that the user means CPU usage, webWalking isn't very CPU intensive after it calculates the route. It does consume 200-300MB ram, but that is to be expected

First of all, I'd suggest to use ConditionalSleeps where applicable. Many beginning scripters tend to put their codebase into one giant loop with a lot of condition checking

A smarter way is to split up your script into 'Tasks' or 'States' paired with a getTask(), getState(), or similar.

When a task has been executed you conditionalsleep until a certain condition is met (or it times out). Using this method I can easily run 50 clients on a modern quad core CPU

 

 

would like to know more
i use states and still get a high cpu/ram usage

  • Like 1
Posted
34 minutes ago, Soldtodie said:

To use States isn't faster or less resource expensive... It's just cleaner to read... If you look at the code it's slower and uses more resources. :facep:

Exactly what I mean, having code that is clean to read will result in it being easier to find the bottleneck.

  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...