Skip to content
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

Optimise ProcScheduler.Delays #1607

Closed

Conversation

amylizzle
Copy link
Collaborator

Was trying to figure out why goon was slow, came across non-optimal code. Was compelled.

Switches the spawn() and sleep() task scheduler to use a sorted list of tasks, and do binary insertion instead of unsorted adds.
This should change the time complexity as: best/avg/worst
spawn()/sleep() becomes O(1)/O(log2(n))/O(log2(n)) from O(1)/O(1)/O(1)
tick processing becomes O(1)/O(n_T)/O(n_T) from O(n)/O(n)/O(n) where n_T is the number of tasks that would resume this tick, and n is just the number of tasks queued.
Best case is O(1) because we always gotta check the first task unless the task list is empty, but we gotta check that too so O(1)

@ZeWaka
Copy link
Collaborator

ZeWaka commented Jan 4, 2024

reminder to use SortedList instead, just for posterity

@amylizzle
Copy link
Collaborator Author

reopen with less fucked up git history

@amylizzle amylizzle closed this Jan 4, 2024
@amylizzle amylizzle deleted the faster_proc_scheduler branch February 9, 2024 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants