SquidDev-CC / CCTweaks

Random additions to ComputerCraft (somewhat deprecated, use CC-Tweaked if you're on Minecraft 1.12).
MIT License
12 stars 2 forks source link

Network optimisations #48

Closed SquidDev closed 9 years ago

SquidDev commented 9 years ago

It might also be worth considering changing the use of getMetadata (TileGeneric method) to getBlockMetadata (TileEntity method) as this, and the getBlock equivalent implement caching.

ElvishJerricco commented 9 years ago

I do think having a set of connections is the most efficient way of doing this. It's much better than traversing the entire network multiple times for any change, which is what vanilla CC does.

SquidDev commented 9 years ago

The trouble is that it is much harder to then find connections from a node, and so to send a message you end up iterating the connection map once for every node on the network - which isn't optimal.

ElvishJerricco commented 9 years ago

I think that operation is rather minimal. The advantages of remembering connections as a set are fairly valuable I think

SquidDev commented 9 years ago

You're probably right. I'll profile everything later today to see if there are any hot spots though.

ElvishJerricco commented 9 years ago

For instance, in creating new networks when a node is removed, all that needs allocating is the new network objects. The connections get to be transferred from one to the other very efficiently. And especially joining two networks is really efficient this way.

SquidDev commented 9 years ago

Looking at OpenComputers, they use Map<INetworkNode, Set<Connection>>. I don't want to copy and paste their network infrastructure, but it is pretty well written.

Also, they've copied my idea of using markdown as an in-game documentation format. :frowning:.

I've profiled and it isn't an issue at all though. There could be some tiny render optimisations todo, but not a priority.