secondlife / viewer

🖥️ Second Life's official client
GNU Lesser General Public License v2.1
213 stars 53 forks source link

Lua: Many scripts at once can degrade performance #2917

Open AtlasLinden opened 1 month ago

AtlasLinden commented 1 month ago

Environment

Second Life Release 7.1.12.11247901645 (Develop+Lua build)

Description

Running many ongoing scripts at once can cause the performance to drop considerably. How many is many? This depends on the script.

Reproduction steps

Here's a script that can cause this performance drop after running only a few copies of it consecutively (may depend on machine for exact number):

for i = 1, 200 do
    LL.sleep(0.1)
end

A clip of multiple copies of this script running: https://gyazo.com/81abbb41d5a26ff9c0968bf0150dcb18

nat-goodspeed commented 1 month ago

I'd be curious if you replace LL.sleep(0.1) with:

Timer = (require 'timers').Timer
...
    Timer(0.1, 'wait')

A pending changeset removes LL.sleep(), which is undesirable for a Lua script because it blocks the whole script, instead of blocking just the calling Lua coroutine.

Another pending changeset presents (e.g.) timers.sleep(0.1), instead of the above Timer(0.1, 'wait') API.

maxim-productengine commented 3 weeks ago

Fixing https://github.com/secondlife/viewer/issues/2884 should have fixed this one too (or at least significantly improve performance). I can now run 20-30 scripts from the description without getting freeze.