Is is worth turning a script off that is not doing much?
|
|
Monica Balut
Beam-Me
Join date: 18 Feb 2007
Posts: 311
|
08-19-2008 11:58
I have two scripts that interact in a HUD. The main script does all the heaving hitting: timers, contols, listens etc. The auxiliary script just sits around most of the time waiting to respond to an occasional link_message request from the main script which usually involves reading a notecard, checking for the integrity of the data and sending some result back to the main script. This HUD will be working in some pretty laggy environments where the server can be struggling to keep up.
I know that running scripts take resources and have thought of keeping the aux script turned off most of the time and only have the main script turn it on when it needs it. Do you think there is much to be gained in doing that versus the cost of the extra code and the response hit of turning a script on and off?
|
|
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
|
08-19-2008 12:21
Worry first and foremost about making efficient scripts. Turning off unused scripts is good, but usually bad coding or a resource-hogging implementation is to blame for lag.
|
|
Monica Balut
Beam-Me
Join date: 18 Feb 2007
Posts: 311
|
08-19-2008 15:57
The fact that I am asking this question implies that I am already trying to eek out every bit of efficiency from my scripts. So my question remains open.
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
08-19-2008 19:52
There really is not a good, all around, blanket answer to the question. It also takes resources to turn a script off and on. I seem to recall turning off and on a script a long time ago. But in that case, it was a script that was only used once in a blue moon. Probably would not code it the same way now. It is very rare for me to actually fill a script all of the way and it is better to just throw the extra code into the main script. One larger script uses less resources then two smaller scripts. Even an empty script uses resources. But even this rule isn't set in stone because you have to figure in readability also. So no one can really give you an answer that would apply in all circumstances. The important thing is that you have gotten to the point of being aware of the possible impact of your scripts and you are trying to write sim friendly code. EDIT: It might be a decent question to fire off to Kelly Linden. God knows I asked him enough sim impact questions when I first started scripting. Does the simulator still process a script that is turned off, as in, does it still have to stop and ask if the script is turned on or not? Or is the script truly invisible to the simulator when it is turned off?
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
|
08-19-2008 21:34
Scripts don't take up processing time while not running, but they do still reside in memory as long as they're in some rezzed object. It's not going to severely impact sim performance to have them all on unless the total script count is like 10,000, depending on the sim. I've considered turning off utility scripts in my HUD before, but in reality, doing so would just interfere with their normal operation, so it's not feasible half the time. The results are minimal compared to the required effort.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-19-2008 22:06
When you pause scripts there are often timing issues when you try to wake them up again, and I'm not sure but there MIGHT be an issue with their link message queues filling up (I don't know if link messages to paused scripts are discarded or queued in the usual manner). If the messages DO queue up to the limit and then start getting discarded for paused scripts, the script is going to need to process at least one before new messages can get in without being discarded as well. So I'd be careful if you are using paused messages that depend a lot on timely link messaging.
Also, to avoid race conditions (where important) it should really only be the same script that both pauses and resumes a given script, and since a script can't wake itself up, it has to be a different one (e.g. your main script that needs requests processed from time to time).
I never worry about this for small, simple systems. When I create larger systems that require a lot of scirpts (e.g. dance machines and such that really need one script per user and are intended for multiple simultaneous users), I try to pause all the scripts that aren't needed. For example, if I want to build a dance machine that could handle 30 avatars at once, I'd rather not have 28 idle scripts running when only two people are dancing.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-19-2008 22:08
From: Tyken Hightower Scripts don't take up processing time while not running.... Hmm. Well, actually the Top Scripts window shows them as using a small amount of script execution time. That CAN add up when you have bunches and bunches of them. Maybe it's just a time accounting thing, because that's certainly not the way it SHOULD be (especially since SL is event-based).
|
|
Viktoria Dovgal
…
Join date: 29 Jul 2007
Posts: 3,593
|
08-19-2008 22:11
One reason why it might be worth the bother to stop the script is if you are passing around link messages for other purposes (or other scripts could be passing messages into that prim). In an environment like that, the idle script still has to process at all them just to make sure it has nothing to do.
Scripts get reset if they are stopped during a sim restart (less of a problem for attachments but it's been reported to happen), so you don't want to mess with that if there is any stored stuff you care about in there. That could be offset by using some kind of protocol in the link messages (e.g, sneak some magic number into the number or key, if those are otherwise unused) so irrelevant ones can be rejected early.
|
|
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
|
08-19-2008 22:24
If the script is doing *something* then you probably don't want to turn it off. If it isn't doing anything at all then should you turn it off? ---> obviously yes.
_____________________
http://slurl.com/secondlife/Together
|
|
Monica Balut
Beam-Me
Join date: 18 Feb 2007
Posts: 311
|
08-20-2008 16:22
Thanks for the inputs folks. I think I'm going to leave the aux script running. The reason I needed to break this up, as is often the case, is that my main script is getting too big so I carve out little used code. Compared to the load of the main script, running the aux script which just sits around waiting for link messages will have minimal impact. But adding the extra code to turn the aux script on and off will push the main script in a direction I want to avoid. I'm already tight for memory there.
|