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

Fix loop scheduler #1

Merged
merged 6 commits into from
Jan 22, 2024
Merged

Fix loop scheduler #1

merged 6 commits into from
Jan 22, 2024

Conversation

metrowaii
Copy link
Contributor

There are two problems with the current loop scheduler. The first being that the order of systems after the initial table.sort was non-deterministic. The second being that the logic for cycle detection was incorrect.

To solve the first problem I switched the "_systems" table from a set to a list. Switching it to a list should not have that big of an impact on performance as games will most likely not have more than a few hundred systems (if that). I also added logic to handle the case where system names are equal - in that case we simply fall back to the original unordered list systems effectively relying on the order provided by the user.

The second problem came up when we had a system with dependencies on other systems. If the initial table.sort call returned an order such that this system (the system with dependencies on other systems) appeared first in the list the cycle detection logic would incorrectly error. For example if we had three systems, systemA, systemB, and systemC, and systemA had a dependency on systemB. If the initial sorting returned an order such that systemA appears first, systemB appears second and systemC appears last then by the time systemB is to be scheduled it would see that systemA is still in the explore phase and throw an error for a cycle which is incorrect.

I overhauled the scheduling logic to use a more straightforward approach - recursive DFS with colors or phases in this implementation.

@metrowaii metrowaii self-assigned this Jan 7, 2024
@LastTalon LastTalon added this to the v0.7.1 milestone Jan 9, 2024
@LastTalon LastTalon removed their request for review January 17, 2024 22:51
@metrowaii metrowaii merged commit 4aa29be into main Jan 22, 2024
6 checks passed
@metrowaii metrowaii deleted the fix-loop-scheduler branch January 22, 2024 08:03
jackTabsCode pushed a commit that referenced this pull request Jan 31, 2024
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.

4 participants