theoretical question about performance
|
Kaylan Draken
Registered User
Join date: 2 Dec 2006
Posts: 127
|
10-15-2009 10:07
H i all,
i have a theoretical question about performance i hope someone can answer.
What is better and why?
if i ask in state entry a OwnersKey and but in a variable and every time i have to check if the detectedkey is equal to the Owners i use the variable. (if llDetecedKey == variable)
or every time i do check if i compare detectedkey against the owner (if llDetectedKey==llGetOwner)
Think the first one will be little faster but use little more memory (the variable) second one is little slower (have to get the ownerskey) but use little less memory.
off course with only 1 script and 1 variable it don't really mater but with lot of scripts and each script will lot of checks it could matter especially with new script limits they want to implement. (in the example i used owners key but it can also be with another key)
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
10-15-2009 10:17
I've wondered about that, too. I think (aka: guess) that it's probably better to use the llFunction() instead of a variable for things that the sim has handy. Owner key, position, object name, stuff like that it knows and can probably get at pretty quickly. If you're compiling with mono and have a bunch of copies of the script in the same region, it's probably the most efficient way to go. edit: somebody like Strife would be a good one to comment about this stuff. /me dangles a cookie from a string, hoping to lure Strife into the thread. From: Kaylan Draken i have a theoretical question about performance i hope someone can answer.
What is better and why? More efficient is better, because it's more efficient! 
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
Nika Talaj
now you see her ...
Join date: 2 Jan 2007
Posts: 5,449
|
10-15-2009 10:38
Now *I* would have thought the variable would give you better performance, being in local memory. If the script cares about the Owner, I usually set a global variable owner_key, in the init routine, and be sure its invoked both in state_entry and by the on_rez event.
Lately I've been doing some things that could be deeded objects (teleporters, etc.), and I've begun shying away from functionality that depends on "owner", since it seems you never see that functionality again once it's deeded.
If LSL were a compiled language, the two would be equivalent. As it is, the performance may differ on this between LSL and Mono; such a minor effect though, that the difference would be extremely tedious to measure.
|
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
|
10-15-2009 11:27
The function is more reliable if what you really need is the current owner: it's impervious to later changes in the script that might cause the variable to be incorrect.
A variable is more efficient in both time and space, if it's used more than once or twice. The variable takes space, but a function call takes more space than a variable reference.
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
10-15-2009 11:46
From: Lear Cale A variable is more efficient in both time and space, if it's used more than once or twice. The variable takes space, but a function call takes more space than a variable reference. For space, I'll buy that with the exception about having multiple copies of a mono-compiled script on a sim, sharing their code space. For time, I'm not as convinced - anything that doesn't have a "delays script for N seconds" on it is likely something that the sim can do pretty quickly.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
10-15-2009 11:52
I think that the difference in the generated code is marginal, and each variable is another datum that must be packed and unpacked on sim crossing.
|
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
|
10-16-2009 09:32
From: Meade Paravane For time, I'm not as convinced - anything that doesn't have a "delays script for N seconds" on it is likely something that the sim can do pretty quickly. Yes, both pretty quickly. But I'll wager that a variable reference is faster than a function call. Enough to matter? No, except inside a tight loop. Otherwise, the overhead of invoking the script's handler is far more significant. I find that with few exceptions, the biggest impact of a script is its idle time -- the 2 microseconds even a script with no handler to run takes in every pass through the list of scripts. Most of the time, most scripts have nothing to do, and when they do have something to do, it's really very little. Notable exceptions include nonphysical vehicles, AOs, and of course, poorly written scripts. I have no experience with weapons systems, but certain kinds of these may also need a lot of CPU. But, in general, getting a sim's script usage down mostly involves reducing the number of scripts, without too much regard for what the script is actually doing. It's too bad that the overhead for a dormant script is so high.
|
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
|
10-16-2009 09:38
From: Argent Stonecutter I think that the difference in the generated code is marginal, and each variable is another datum that must be packed and unpacked on sim crossing. Good point. And above, I made the mistake of making a factual answer rather than giving advice.  I use llGetOwner() unless there's a specific reason to use a variable. I use a variable if I have a reason to refer to the previous owner. (For example, this is necessary to detect actual change in ownership, because the CHANGED_OWNER event fires for the original when "buy" is used with "buy copy", oddly enough. It's also necessary to refer to the original owner after deed-to-group.) I might also use it in special cases where memory is at a premium. As a software engineer for 30 years, I've spent a lot of time teaching new hires that efficiency is usually not the primary concern, and when it is, first optimize algorithms, and then optimize code as needed. (Emphasis on the "as needed".) Clarity and maintainability really matters. Efficient *designs* are important. Whether the function or variable is more efficient might be interesting, but it rarely matters.
|
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
|
10-16-2009 09:47
From: Meade Paravane For space, I'll buy that with the exception about having multiple copies of a mono-compiled script on a sim, sharing their code space. This is a good point, from the standpoint of minimizing memory use on the sim. From the standpoint of maximizing the memory available for your script's data, the sharing is ignored: the size of the code counts against your "stack-heap collision" limit regardless.
|