Open immibis opened 4 years ago
Take what I'm about to say with however many pinches of salt you deem necessary, as I'm obviously a little biased. Just a couple of points:
It's worth noting that this code runs on the computer thread(s). Assuming you're running on a multi-threaded machine, this shouldn't have any (major) impact on TPS.
A server I help manage - SwitchCraft - has about 500 computers running and several modem sniffers (arrays of hundreds of modems to monitor all modems channels) and runs at a solid 20 TPS. It is running on a beast of a machine, though when profiling, modems have never been a hotspot.
Keep a separate receiver list per port
This is pretty appealing, as most channels will only have one listener (the computer with the same id as the channel). Still worth noting that some of them (CHANNEL_BROADCAST
, and CHANNEL_GPS
) will be open on most, if not all, modems. Messages sent on these channels are less frequent though, so it's still probably a net gain.
Use a quad-tree structure to only consider receivers that are in range or close to it.
Modems on turtles and pocket computers can move position. Most of the time it's not going to change nodes in the quad-tree, but there is some bookkeeping overhead which would need to happen each tick.
Honestly, the big performance problem with wireless modems isn't the routing itself but the fact that every computer who receives a message needs to queue an event and execute some Lua code.
As an aside, the wired network code is terrible - we use dijkstra to route packets through the network, so it's O(n lg n)
(ish), rather than the O(n)
here. Though typically wired networks will be smaller than wireless ones.
Seen here: https://github.com/Zundrel/cc-tweaked-fabric/blob/fabric/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/WirelessNetwork.java
the wireless network just loops through all modems to find ones that are able to receive the message.
It's good enough, but to support very large servers it would be good to optimize it. Suggestions: