From: Sindy Tsure
I'm not sure I totally agree with this...
What Meade wrote on the previous page helps cut down the complexity of the script and saves a bit of static memory but LSL uses (I think - please correct me if I'm wrong) pass-by-value when calling functions. So, although the script is cleaner, it's more expensive at run time. This is why she said to be careful of calling it in a tight-loop...
Either way, whether it's scattered throughout the code or contained in one function, the 'if' is still going to get executed every time. If you're passing a string to a debug function, LSL is going to make a copy of that string (eating memory at least temporarily) each time it's called. If you're not passing strings, you're still adding the cost of pushing ints and a new stack frame. All of these are more expensive than doing it in-line..
If you're actually passing the string to a different script, that's even more expensive than doing it all within one script.
That said, I use debug functions like this, too - ain't saying they're bad, just that people should understand the implications.
for the second paragraph I was using Alicia's code to point out that she was still doing all the proccesing in her base script (sending the debug to a function, deciding wher or not to parse it THEN offloading it to another script... when it'd have been more effective just to send the debug string to another script, and let it decide parsing.
in the orignial example that Meade and I both wrote in different thread, we couldn't eliminate the string, but we could kill all extra the bytcode for the if statement and it's associated reference to DEBUG and the bytecode for the say, which presumably is more than a call to a seperate function to handle it all. it could probably be reduced farther with a well placed global or two.
you are absolutley right about tight loops, if a block is being called inside a loop far more consistently than outside it it may be better to write it all out, at least for the loop. but that seems like a pretty rare case to be using it in both... any block in a loop is a single block (if you call the same set of actions more than once in a loop, the loop could probably use rewritting)
if I were going to offload all Debugs to a seperate script I'd probably use the folowing
//--eleminates bytecode overhead for each variable in link messages except the debug code
fDebug( integer vIntDebug ){
llMessageLinked( LINK_THIS, vIntDebug, "DEBUG", "" );
//-- key could be added for more complex debugging messages and variable handling
}
and call it with
fDebug( <some number> );
and the debug handler script would conatin
list gLstCodes = [<code numbers paired with messages> ];
link_message( integer vIntNull, integer vIntCode, string vStrMessage, key vKeyExtendedInfo ){
if ("DEBUG" == vStrMessage){
//-- procces code to message and ouput to llOwnerSay
}
}
several variations are possible.... and I'd only use something like this if it was intended to be left in, for instances where I intend to remove all debug commands before offering it up, I'd just use the function, and not even bother with a test (or as I often do, just use owner says, and remove them later.)