Skip to content
This repository has been archived by the owner on Dec 4, 2022. It is now read-only.

Add delay function for Lua scripts #24

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

Doomsdayrs
Copy link
Member

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

Utilizing the kotlin time library, establish method to delay a scripts
 process for a certain amount of milliseconds
@Doomsdayrs Doomsdayrs requested a review from TechnoJo4 November 3, 2021 03:56
var currentTime: Long
do {
currentTime = Clock.System.now().toEpochMilliseconds()
} while (startTime + milliseconds > currentTime)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 60ms difference is insignificant, especially when waiting for e.g. a rate limit. A web request might take much longer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, Is this acceptable to merge or?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants