Jump to content

Events && Performance


RoboMat

Recommended Posts

Okay so with the new events like EveryTenMinutes we aready have a powerful Event which doesn't eat much performance. I still have questions about the performance though.

 

Would there be any difference between

function one()...end function two()...end function three()...end Events.EveryTenMinutes.Add(one);Events.EveryTenMinutes.Add(two);Events.EveryTenMinutes.Add(three);

and:

function one()...end function two()...end function three()...end function master()     one()     two()     three()end Events.EveryTenMinutes.Add(master);

Will there be any noticeable impact if I exit out of the functions early? I actually do that at the moment in all of my mods... I try to exit out as soon as possible by testing different boolean states at the beginning of the function for example. For example like this:

function doStuff()      if noStuffToDo then              return;      end... -- else do much more stuff hereendEvents.OnTick.Add(doStuff);

Of course it has to check the boolean value each time it is called but would this have any recogniseable impact on performance or is it negligeable?

Link to comment
Share on other sites

Okay so with the new events like EveryTenMinutes we aready have a powerful Event which doesn't eat much performance. I still have questions about the performance though.

 

Would there be any difference between

function one()...end function two()...end function three()...end Events.EveryTenMinutes.Add(one);Events.EveryTenMinutes.Add(two);Events.EveryTenMinutes.Add(three);

and:

function one()...end function two()...end function three()...end function master()     one()     two()     three()end Events.EveryTenMinutes.Add(master);

Will there be any noticeable impact if I exit out of the functions early? I actually do that at the moment in all of my mods... I try to exit out as soon as possible by testing different boolean states at the beginning of the function for example. For example like this:

function doStuff()      if noStuffToDo then              return;      end... -- else do much more stuff hereendEvents.OnTick.Add(doStuff);

Of course it has to check the boolean value each time it is called but would this have any recogniseable impact on performance or is it negligeable?

Hmm good question.

 

OnTick is very dangerous to use with average complex functions I think. I'm counting tick and for every tenth, I do the functionality to avoid fps drops

Link to comment
Share on other sites

good questions, I guess the first part about 3 events or 1 even isn't going to make much difference on your performance.

 

the second part, about exiting as soon as possible is a good coding rule you should indeed do.

the time used for testing 1 boolean isn't so great and I guess is indeed negligeable.

 

also on the OnTick thingy, if it doesn't need to be used EVERY tick it is indeed possible to use something like

if (somecounterfromsomewhere mod 20 == 0) then ...... end

ps. arcane you just wrote that message at the moment I did to :P

Link to comment
Share on other sites

The difference would be so negligible so as not worth worrying about tbh...

 

Stay away from using OnTick if possible for any 'gameplay stuff' if every ten minutes will work for you, since tick is every game update regardless of game speed, and you'd need to factor the game speeds in yourself.

Link to comment
Share on other sites

The only events I've noticed dragging down the performance on my old laptop are the draw events. And it usually takes a lot of for loops to do it.

 

Still, it would be nice to have an EverySecond event. EveryTenMinutes is usually too infrequent and OnTick too frequent.

Link to comment
Share on other sites

  • 3 weeks later...

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
×
×
  • Create New...