Repository: SkriptLang/Skript

Issue #891: Huge performance loss with adding values to list
Created: 2017-09-24T06:20:21Z
I noticed an incredible amount of performance loss when trying to create some custom world editing commands.  The problem become extremely evident when making larger edits (radius greater than 5).
The super slow way:
loop blocks in radius {_rad} around location of player:
  add loop-block to {blocks::*}

The 100+ times faster way:
set {_index} to 0
loop blocks in radius {_rad} around location of player:
  set {blocks::%{_index}%} to loop-block
  add 1 to {_index}

I found that the first way could only process about 100 blocks in the time the second way can process about 10000.  I'm not sure why such a drastic difference is coming but i felt it was significant enough to report here as a possible issue.  (or at least help others having lag issues with the workaround I found to drastically help)  My thoughts are that the lag is coming from searching the database for the next usable index when adding a value to a list since that is really the only thing different between the two except the second example actually has more lines of code to process by runs 100 times faster literally.

Duplicate issue #4561: Adding a Value to a List Is Slower
Created: 2022-01-31T16:07:39Z
Skript/Server Version
31.01 16:01:31 [Server] INFO [Skript] Skript's aliases can be found here: https://github.com/SkriptLang/skript-aliases
31.01 16:01:31 [Server] INFO [Skript] Skript's documentation can be found here: https://skriptlang.github.io/Skript
31.01 16:01:31 [Server] INFO [Skript] Server Version: git-Paper-"cc43ba7" (MC: 1.17.1)
31.01 16:01:31 [Server] INFO [Skript] Skript Version: 2.6.1
31.01 16:01:31 [Server] INFO [Skript] Installed Skript Addons: 
31.01 16:01:31 [Server] INFO [Skript]  - Skent v3.1.0
31.01 16:01:31 [Server] INFO [Skript]  - skript-yaml v1.4
31.01 16:01:31 [Server] INFO [Skript]  - SkBee v1.14.0 (https://github.com/ShaneBeee/SkBee)
31.01 16:01:31 [Server] INFO [Skript] Installed dependencies: None

Bug Description
When you add a value to a list variable, it takes longer. See Steps to Reproduce for more context
Expected Behavior
It takes nearly the same amount of time to add to a list as anything else.
Steps to Reproduce
Make some code (like the code below) to loop a bunch of times, then add to a list.
command /test:
    trigger:
        broadcast "&7------------"

# Test 1
        set {_now} to now
        loop 500 times:
            set {_var::%loop-number%} to loop-number
        broadcast "&e1: %difference between now and {_now}%"

        delete {_var::*}

# Test 2
        set {_now} to now
        loop 500 times:
            add loop-number to {_var::*}
        broadcast "&e2: %difference between now and {_now}%"

# Test 3
        set {_now} to now
        loop {_var::*}:
            add loop-value to {_var2::*}
        broadcast "&e3: %difference between now and {_now}%"

        delete {_var2::*}

# Test 4
        set {_now} to now
        loop {_var::*}:
            add 1 to {_loops}
            set {_var2::%{_loops}%} to loop-value
        broadcast "&e4: %difference between now and {_now}%"

Results of the code above:
31.01 15:57:17 [Server] INFO MinecraftMan1013 issued server command: /test
31.01 15:57:17 [Server] INFO ------------
31.01 15:57:17 [Server] Startup 1: 0.01 seconds
31.01 15:57:17 [Server] Startup 2: 0.21 seconds
31.01 15:57:18 [Server] Startup 3: 0.17 seconds
31.01 15:57:18 [Server] Startup 4: 0.01 seconds
31.01 15:57:25 [Server] INFO MinecraftMan1013 issued server command: /test
31.01 15:57:25 [Server] INFO ------------
31.01 15:57:25 [Server] Startup 1: 0 seconds
31.01 15:57:25 [Server] Startup 2: 0.14 seconds
31.01 15:57:25 [Server] Startup 3: 0.18 seconds
31.01 15:57:25 [Server] Startup 4: 0 seconds
31.01 15:57:28 [Server] INFO MinecraftMan1013 issued server command: /test
31.01 15:57:28 [Server] INFO ------------
31.01 15:57:28 [Server] Startup 1: 0 seconds
31.01 15:57:28 [Server] Startup 2: 0.1 seconds
31.01 15:57:28 [Server] Startup 3: 0.1 seconds
31.01 15:57:28 [Server] Startup 4: 0 seconds
31.01 15:57:29 [Server] INFO MinecraftMan1013 issued server command: /test
31.01 15:57:29 [Server] INFO ------------
31.01 15:57:29 [Server] Startup 1: 0 seconds
31.01 15:57:30 [Server] Startup 2: 0.11 seconds
31.01 15:57:30 [Server] Startup 3: 0.1 seconds
31.01 15:57:30 [Server] Startup 4: 0 seconds
31.01 15:57:31 [Server] INFO MinecraftMan1013 issued server command: /test
31.01 15:57:31 [Server] INFO ------------
31.01 15:57:31 [Server] Startup 1: 0 seconds
31.01 15:57:32 [Server] Startup 2: 0.12 seconds
31.01 15:57:32 [Server] Startup 3: 0.14 seconds
31.01 15:57:32 [Server] Startup 4: 0 seconds

Errors or Screenshots
No errors when reloading script
31.01 16:07:20 [Server] INFO [Skript] Reloading aatest.sk...
31.01 16:07:20 [Server] INFO [Skript] Successfully reloaded aatest.sk. (7ms)

Other
No response
Agreement

 I have read the guidelines above and confirm I am following them with this report.

Closing comment (2022-01-31T16:16:58Z): Duplicate of #891