Are listeners actually expensive, or is this a myth?

Creating scripts
User avatar
Mike Lorrey
Posts: 361
Joined: Sun Sep 04, 2016 5:40 pm
Has thanked: 71 times
Been thanked: 269 times

Re: Are listeners actually expensive, or is this a myth?

Post by Mike Lorrey »

Tess Juel wrote:
Sat Aug 21, 2021 4:25 pm
IntLibber Brautigan wrote:
Sat Aug 21, 2021 3:30 pm
In device 1:

Code: Select all

integer setupchan = 999;
integer chan = (integer)llFrand(999999);
One question about this snippet. In SL it's consdiered good practice to always use negative channels for scripts so it would be

Code: Select all

integer setupchan = -999;
integer chan = (integer)llFrand(-999999);
Is opensim different there?
You are correct, negative channels are recommended, though most novices dont get them, but thats a separate topic. However! it was claimed years ago that negative channels could not be listened into by others, which is blatantly false.
User avatar
Mike Lorrey
Posts: 361
Joined: Sun Sep 04, 2016 5:40 pm
Has thanked: 71 times
Been thanked: 269 times

Re: Are listeners actually expensive, or is this a myth?

Post by Mike Lorrey »

Tess Juel wrote:
Sat Aug 21, 2021 4:38 pm
Oren Hurvitz wrote:
Sun Jul 11, 2021 7:15 am
The usage cost appears to be pretty low, at least if not too many messages are being sent. Sure, OpenSim has to go over all of the potential listeners, but it can probably do this in a few ms. It only becomes a problem if you have a large number of listeners (hundreds?), or if you send many messages per second.
Tell me if I understand this right. Let's say I have a master switch that turns on and off street lights across the entire sim. Or a master texture changer that switches between seasonal foliages for all trees in the sim. There may well be hundreds, maybe even more than a thousand receivers but there won't be a message sent every day or even every month. Are all those open listens still likely to cause problems?
Yes, the main reason to turn off listens when not in use is that a) sloppy scripters tend to use the same channels for a lot of things so you get a lot of cross-talk between different types of scripts, hence the random channel code I posted, b) in regions where there are multiple content owners like a sim with tenants, you definitely don't want everyones scripts talking to each other unintentionally. Using the channel randomizer code makes sure that the fewest number of scripted objects will hear message chatter, so you'll get the least lag when they are talking to each other.
These users thanked the author Mike Lorrey for the post (total 3):
Ilan TochnerTess JuelChristine Nyn
User avatar
Christine Nyn
Posts: 71
Joined: Sat Mar 07, 2020 10:20 pm
Has thanked: 218 times
Been thanked: 126 times

Re: Are listeners actually expensive, or is this a myth?

Post by Christine Nyn »

To add to Mike's very useful overview:

Positive channels can be accessed directly from chat either by using, for example /21 <your message>, or as an embedded part of a gesture. Negative channels can only be accessed by script. Thus there exists a chance that positive channels used for script control could be unintentionally interfered with by others within chat range of the scripted object. Negative channels range from -1 to -2147483646, over two thousand million possibilities, so as long as a fairly high randomly generated negative channel is used the chances of it being listened to or accidentally duplicated on a region are so small as to be almost non-existent.
These users thanked the author Christine Nyn for the post (total 2):
Tess JuelGraham Mills
User avatar
Snoots Dwagon
Posts: 422
Joined: Mon Jul 30, 2018 9:45 pm
Has thanked: 442 times
Been thanked: 779 times

Re: Are listeners actually expensive, or is this a myth?

Post by Snoots Dwagon »

Took me a while to answer this. I been busy lately. :D

Long ago in a grid far, far away, listeners were lag fiends. They were poorly constructed and using even a dozen or two listeners could create notable "lag".

Then someone at that far land wised up and fixed that problem, and it did cease to exist.

That said, there are things to consider:

* Listening on channel 0 (main chat) is always more costly than listening on other channels, since that script will listen to everything that is said by any avatar (unless directed to do otherwise). At the least it will listen to everything the owner says. It is thus better to listen on non-zero channels.

* Use positive channels to listen to avatar commands, negative channels to listen to other script commands.

* Big savings tip: If you have multiple items listening to the same channel (such as a series of street lights all over a town)... it is possible to link all those items together and use llMessageLinked() along with a single listen. Not only is llMessageLinked() less "costly", it only works when it's triggered (ie, it's not sitting there waiting to see if something has chatted something).

* Sometimes it is possible to use ONE SCRIPT, and LINK-enabled coding to accomplish a task. In the fore-mentioned example of street lights, if you use listen or llMessage Linked either one, you will need a central recognition script and an individual receiver script in each light. HOWEVER, if you use only one single link-enabled receiver script (your listen), and then have the script locate each linked item and trigger its function, you can literally turn every street light on and off from one centralized script. This isn't "easy" coding but it's not especially complex, and it works very well. The main advantage of this linked-action scripting is that it reduces the number of scripts significantly, thus increasing overall performance.

The English-language concept works like this:

Listen for on/off command
Ascertain total number of linked prims
loop through those prims and look for prims named STREETLIGHT
when a STREETLIGHT prim is found, turn it on or off as commanded (using a llSetLinkPrimitiveParams function)
finish loop

It's surprising how often this scripting trick comes in handy. Once one gets the concept down, the linked function concept can significantly reduce script count on some regions.
These users thanked the author Snoots Dwagon for the post (total 2):
Tess JuelIlan Tochner
~~~~~~~
I'm a dwagon in real life too. (Ask my sister, who totally agrees.)

~~~~~~~
Post Reply