Jump to content
Sign in to follow this  
gc8

faster scripts/code execution?

Recommended Posts

can you make arma scripts run faster? i wrote script so big it takes a few seconds to just run it through once. its not that i dont know how to optimize , its just that having lets say a loop which runs through all units in game, executing a piece of code on each unit, takes several seconds to complete. which means that the visual result of the script is really bogged down.

clearly the scripts timeout easily on arma because the game itself doesnt come to halt, the script just hangs on background while rest of the game goes on. so i think arma should be able to increase script processing time?

has anyone ever had the same problem?

thanks

Share this post


Link to post
Share on other sites

Oh dear if it takes several seconds..

a. your computer is really crap

b. you are doing something wrong

Share this post


Link to post
Share on other sites
Oh dear if it takes several seconds..

a. your computer is really crap

b. you are doing something wrong

Depends how many units he has running about.

Share this post


Link to post
Share on other sites
Depends how many units he has running about.

still pretty sure as .kju said you can improve it by using different approach, unless it is something really stupid of course.

Share this post


Link to post
Share on other sites

This code typically places about 400 markers, which takes about 2.7 seconds. Visually when looking at the map that's a lot of time. instead of instant map update you get to watch dots appearing and forming something, and that's not what i wanted...

It takes only around one second when map is closed or when all marker code in the loop is removed..... (still second is lot for loop of just 400)

wish there would be other way to draw on the map than using markers but according to my knowledge there isn't. or is there?


_starttime = time;

{
_m = _x select 0;
_dpos = _x select 1;
_mColor = _x select 2;

_m = createMarker [_m,  _dpos ];

_m setmarkertype "dot";
_m setmarkercolor _mColor;

} foreach _tileMarkersNew;

["placing new markers took: %1 seconds", time - _starttime] call dbgmsg;

---------- Post added at 16:25 ---------- Previous post was at 16:22 ----------

Oh dear if it takes several seconds..

a. your computer is really crap

I have Core i7 2600K so it's not bad at all :)

Share this post


Link to post
Share on other sites

a) when do you execute this?

b) what other code is running at the same time?

c) how is your general fps without the script?

Share this post


Link to post
Share on other sites

Question, do you run this bit of code for every unit? Like in every player?

Share this post


Link to post
Share on other sites
;2386808']a) when do you execute this?

b) what other code is running at the same time?

c) how is your general fps without the script?

a) it's ran from the start at every 20 seconds.

b) A lot..

c) good' date=' around 60fps i think with minor lag spikes at tops but nothing like the delays in the script it self.

---------- Post added at 17:19 ---------- Previous post was at 17:17 ----------

Question, do you run this bit of code for every unit? Like in every player?

just once. (one execvm). but the array it self could have all the players, in the code i posted it just had marker data.

Share this post


Link to post
Share on other sites

I'm somewhat confused by your answers, they seem to contradict each other. Sorry without proper understanding what is that you are doing, I can't help.

Share this post


Link to post
Share on other sites

ok i put the code in empty mission and it ran under 0.1 seconds. so its not the script it self. then i put the test code in the big project i originally had the lag issue with and i put it at the end of init.sqf , when all rest of the scripts have already been executed and it still has no lag. then i put delay of 10 secs before running the test code and now running takes over one second!

which means it lags because of other scripts or units on map....

here's the new test code i used:


// sleep 10; // takes under 0.1 secs to run when run immidiately and over 1 seconds when run after this 10 delay

["Running"  ] call dbgmsg;

_array = [];
_pos = ((getpos player )  ) ;

for "_i" from 0 to 400 do
{
_array = _array + [[_i,_i + 1, _i + 2, _i + 3, [ (_pos select 0) + random 5000, (_pos select 1) + random 5000] ]];
};

_timestart = time;

{

_u = _x select 0;
_u1 = _x select 1;
_u2 = _x select 2;

_m = createMarker [format["m_%1", _u],  _x select 4 ];

_m setmarkertype "dot";
_m setmarkercolor "ColorGreen";

} foreach _array;

["Running took %1 seconds" , time - _timestart] call dbgmsg;


Edited by gc8

Share this post


Link to post
Share on other sites

I don't know why you are getting those delays with sleep, perhaps maybe because the conditions under which you execute are different, this normally doesnt happen so something else must be wrong somewhere.

As for your code, changing _array = _array + [_element] to _array set [_i, _element] can increase the speed of that loop 85 times. On top you can combine marker creation with the array filling in one 400 loop instead of running 2 400 loops. Also there is no reason having 1-4 elements like you have, you increase the size of the array and add unnecessary computations to the already busy loop. You can acquire those values from knowing only 1st element's value after.

As you can see tons of room for optimisation before claiming ArmA is a turd.

Share this post


Link to post
Share on other sites

There is also a nifty guide to code optimisation for Arma2 in the BIKI.

And although I know that the following question is really dumb, but does your scripts also lag without the code you posted above? You don't seem to use any seriously exhaustive commands which could slow down your script for several seconds, so my guess (and the ones of everyone before me) would be that another script is slowing down your overall script execution.

Share this post


Link to post
Share on other sites

thanks guys , you are right about something else slowing the script being tested. I did some futher testing to find out what that is exactly and it turned out to be other heavy scripts that are being run continuously with only small Sleep delays.

So I turned other scripts either off or added 5 seconds delays on every loop that was running and now the test code runs very fast, under a second. pretty good though still not perfect.

it seems that arma queues script's to be executed but this queue is only processed for certain amount of time and then the game moves on. and therefore if your one script is taking lot of processing time then all the rest of your scripts are as well.

i wish arma had command to allow more of this processing time to be given for the scripts. because right now im running high FPS but still have to wait for scripts to run on background. or maybe the whole thing is multithreaded, i don't know.

Share this post


Link to post
Share on other sites

if you have non critical scripts you can spawn them rather than call them. this will create parallel thread. If you call everything then you have to wait in the queue

Share this post


Link to post
Share on other sites
if you have non critical scripts you can spawn them rather than call them. this will create parallel thread. If you call everything then you have to wait in the queue

this is spawned. (Execvm) . but its still processed far slower than the game it self, if you know what i mean.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×