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

Optimize channel computation #8285

Merged
merged 8 commits into from
Dec 17, 2024
Merged

Optimize channel computation #8285

merged 8 commits into from
Dec 17, 2024

Conversation

Technici4n
Copy link
Member

@Technici4n Technici4n commented Dec 16, 2024

  • Optimize the channel computation to make it go from O(N^2) to O(N).
  • Cleanup related code a little bit. Most importantly, choose the same meaning for usedChannels vs lastUsedChannels for both GridConnection and GridNode.
  • Remove booting delay. Note that the API still supports it, and that we might want to add back some sort of delay in the future if necessary.
  • Remove pathfindingStepsPerTick config option.

@shartte
Copy link
Member

shartte commented Dec 16, 2024

I think you mean it goes from O(N^2) to O(N) I hoper

@bk5115545
Copy link

Since the method of jumping the path calculation is essentially what timsort does, I think this will be closer to O(N * N/(average jump size for the current network) + (average path length to controller * number of channel consumers)).

Time contributed from pathing: N * N/(average jump size for the current network). This is an optimization of BFS which is normally N * (edge count).
Time contributed from channel assignment: (average path length to controller) * (number of channel consumers)

Still a crazy improvement over the current implementation but I think if you invented an O(N) graph pathing algorithm then you'd solve the travelling salesman problem so I'm hesitant to believe this is O(N)

@Technici4n
Copy link
Member Author

I think you mean it goes from O(N^2) to O(N) I hoper

Yes 😄

@Technici4n
Copy link
Member Author

The new algorithm is linear time because there are at most 2 jumps. (In theory. I have to double-check that this is true in practice.)

As a side note, BFS and DFS are both linear time traversal algorithms. And BFS can find shortest paths in linear time, the catch is that it only works with unweighted edges.

@Technici4n Technici4n marked this pull request as ready for review December 17, 2024 01:03
@Technici4n Technici4n merged commit 1600e93 into main Dec 17, 2024
6 checks passed
@Technici4n Technici4n deleted the faster-channel-computation branch December 17, 2024 10:55
@bk5115545
Copy link

Is this something that can be backported to 1.20 (I don't know your guidelines on versioning)?

I'd really like to get it into Monifactory and I can do the backport work/make a PR if you're alright with that

shartte added a commit that referenced this pull request Dec 17, 2024
@shartte
Copy link
Member

shartte commented Dec 17, 2024

@bk5115545 Backported as 15.3.0-beta

@bk5115545
Copy link

You're amazing. Thank you!

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.

3 participants