-
-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using 'Contains' for List Variables #2393
Comments
simple code to test function listContains(list: objects, o: object) :: boolean:
loop {_list::*}:
if loop-value is {_o}:
return true
return false
on load:
set {x::*} to integers between 1 and 1000
set {_s} to (unix timestamp of now * 1000)
if {x::*} contains 500:
broadcast "contains - %(unix timestamp of now * 1000) - {_s}%ms"
set {_s} to (unix timestamp of now * 1000)
if listContains({x::*}, 500) is true:
broadcast "listContains - %(unix timestamp of now * 1000) - {_s}%ms" |
@Blueyescat May I ask, what's the |
The contains effect has long been problematic. It's slow and historically has simply not even always worked properly. In this specific scenario (checking contains on a list of objects) the operation the condition is doing has no reason to be 200x slower than the same condition being rewritten as a Skript function. There is clearly some large for optimization and fixes here and given how often this condition is used it should be addressed sooner rather than later IMO. |
Also, looking for variables (specifically locations) does not seem to work using "contains"
{_loc} is even in there twice, still does not find it and never shows "test" Looping works fine:
|
Cannot replicate with following code:function lookup(l: locations, p: player):
log "looking for %{_p}%'s location (%{_p}'s location%) in this list:"
loop {_l::*}:
if loop-value isn't {_p}'s location:
log " %loop-value%"
else:
log " %loop-value% <--- FOUND"
if {_l::*} contains {_p}'s location:
log "found"
else:
log "not found" Output for
Output for
|
Tried on Version 1.13.2/1.14 using Skript 2.4-beta5
Recently I ran a stress test comparing looping list variables to find an object and also using contains to find an object. It seems that looping is actually WAY faster. I don't know why its the case but I was wondering if there could be an enhancement for using 'Contains' with list variables so that its as fast as looping.
The Stress Test:
3000 random strings with 12 random chars each in a list variable
set var to random string out of the list variable
Looping to find the random string:
Looping Speed: Took 3ms on average (2ms-4ms) to find the random object.
Using contains to find the random string:
Contains Speed: Took 600ms on average (500ms-700ms) to find the random object.
The text was updated successfully, but these errors were encountered: