Improve add syntax for lists by saving the last used index#8539
Closed
Shroobz wants to merge 4 commits intoSkriptLang:dev/patchfrom
Closed
Improve add syntax for lists by saving the last used index#8539Shroobz wants to merge 4 commits intoSkriptLang:dev/patchfrom
Shroobz wants to merge 4 commits intoSkriptLang:dev/patchfrom
Conversation
Efnilite
requested changes
Apr 14, 2026
Member
Efnilite
left a comment
There was a problem hiding this comment.
some benchmarks may be nice to show the actual improvement (and whether there is one)
Author
Some auto-formatter ran accidentally Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com>
Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com>
Author
|
I forgot to rename the usages of lastUsedIndex, 1 sec |
Member
Member
|
This is a duplicate of #8519 |
Author
no idea how I didn't see that, sorry |
Member
|
It's okay, we still appreciate your contribution! It's partly my fault for not referencing the issue you referenced (I didn't know it existed :p). Don't let this push you away from contributing in the future! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.





Problem
Adding to lists has been slow due to an O(N) lookup happening every single time a value is added. This means adding N values to a list separately is O(N²), while adding them all at the same time is O(N). This problem is also described in #891
Solution
I (somewhat) solved this problem in 2 ways:
1: Replaced repeated TreeMap.containsKey() calls with HashSet.contains() calls
2: Saving the last used index during an add operation. If another operation is done that could cause a gap in the list, the saved index is reset. This means the O(N) lookup will only happen once a gap can occur or when the server restarts.
Testing Completed
quickTest was completed succesfully. I tested if gaps in lists would get filled and the performance of the code in #891 (the performance is now pretty much the same for setting and adding, adding might even be faster (though I doubt it))
Supporting Information
Completes:: #891
Related: #891
AI assistance: none
p.s. I think some sort of auto formatter ran and removed a double tab around line 242