Building structures
-
I am always between 70-100+ for my cpu. Are people manually building structures to save cycles or are you programming everything? I am in the process of putting more things into memory and refactoring code. I was just curious ...
-
I just restructured everything to use less FIND functions and use the memory for more things, CPU load dropped significantly by it as far is I can currently tell.
-
Do not perform these tasks every tick, spread them out.
Save the last Game.time a given task was performed for room into its memory, wait for an interval + room index (so they'll be staggered) before performing this task again.
-
Another way to save CPU usage is to store the values of the FIND functions into a temporary module. I went from 60~70% CPU usage to about 20~30% with this code:
```
var roomData = {};
Room.prototype.xFind = function(type, filter, sorter)
{
if(roomData[type] == undefined)
_roomData[type] = this.find(type);var back = _roomData[type]; if(filter != undefined) { back = _.filter(back, filter); } if(sorter != undefined) { back.sort(sorter); } return back;
}
```