cheahjs / TerrariaAPI-Server

Fork is now over at https://github.com/NyxStudios/TerrariaAPI-Server
https://tshock.co
32 stars 24 forks source link

More efficient RAM usage #31

Closed MarioE closed 10 years ago

MarioE commented 10 years ago

These commits make RAM usage drop dramatically -- it roughly halves the amount of memory used, or more on Mono.

Main.tile is now a TileCollection with a get/set indexer which returns a helper struct (not a class, as a class proved to be far too slow due to allocation on the heap instead of stack). Properties couldn't be implemented on the struct due to the "Cannot modify the return value because it is not a variable" compile error. Thus, all instances of Tile.frameX, frameY, liquid, type, and wall had to be regex replaced, and a method had to be used. This means that compatibility with plugins that deal with tiles is broken, but I believe the gains are far, far more than the losses incurred by this.

ServerSock.writeBuffer has been removed because it is never used, which saves 256KB of RAM. messageBuffer.readBuffer has been lowered to 1KB instead of 64KB because ServerSock.readBuffer can only hold 1KB, which saves ~16 MB of RAM.

Various client-based classes have been removed entirely, also helping the RAM usage.

Finally, several files have been replaced with files generated from bc's ILSpy, which means that there are no longer millions of tabs in them.

If/when this PR is accepted, I will immediately make the required changes to TShock. (We might want to tick the API version too, perhaps?)