Add delay function for Lua scripts#24
Add delay function for Lua scripts#24Doomsdayrs wants to merge 1 commit intoshosetsuorg:developmentfrom
Conversation
Utilizing the kotlin time library, establish method to delay a scripts process for a certain amount of milliseconds
| var currentTime: Long | ||
| do { | ||
| currentTime = Clock.System.now().toEpochMilliseconds() | ||
| } while (startTime + milliseconds > currentTime) |
There was a problem hiding this comment.
Timers using infinite loops are inefficient and waste CPU time. We should figure out a better way to make a delay function. Furthermore, I don't know if such a function is even needed right now.
There was a problem hiding this comment.
The usage of such a function is to allow scripts to not create network calls too quickly. As this often will lead to website blocking users.
The loop overhead is only 23~ ms on my desktop, and shouldn't be too much more on mobile devices.
Note: Not an infinite loop, as there is a clear end clause.
There was a problem hiding this comment.
@TechnoJo4 Swapping to use kotlin-corutines for the delay call leads to a 62ms overhead. Currently this is far more performant then the other multi platform method
There was a problem hiding this comment.
A 60ms difference is insignificant, especially when waiting for e.g. a rate limit. A web request might take much longer.
There was a problem hiding this comment.
So, Is this acceptable to merge or?
Utilizing the kotlin time library, establish method to delay a scripts
process for a certain amount of milliseconds.
@TechnoJo4 Can you check how long it takes you to run a delay, for me there was an overhead of 23~ ms when using
delay