Garbage collection costing me 15-30 cpu each tick?

  • SUN

    Am I generating too much garbage if during my ~100 cpu I seem to trigger the GC once every tick? It seems to cost me 15-30 cpu at a random execution point.

    Of course I'm not sure this is the garbage collection, but I can't think of any other natural phenomenon that could occur once during every tick at a random execution point.

    I catch it by profiling four cpu usage values for each room phase: init, spawn handling, creep handling and structure handling. None of my rooms normally take more than 15 cpu in any of these phases. Yet there is always one phase in one room, that takes the 15 cpu minimum. For example the init phase is mostly less than 1 cpu, but when the phenomenon hits there with the 15+ cpu, it doesn't hit anywhere else during that tick. Basically the creep handling can go up to 10 cpu in one room, but that's rare. Other phases are 0-3 cpu, usually less than 1, so the effect of this phenomenon is clearly perceived.

    Is this something I am doing wrong in my code, or is there a player whose tick is always executed before mine, he does something wrong and I get the ill-effects, or something else?

  • Culture

    It's normal when the server reload your scripts that it will spike in the cpu. You can put a console.log("Reloaded script") outside your main-loop to see when this happen. It normally happens 3 times after you save your script and then at a random factor, but never every tick, if it do you prob use to much of the stack memory or something.

    I can also see that you use random name generator for your creeps. The function is not optimized to use when you have 100+ creeps and that function alone will spike your script 15-30 cpu each time you spawn a creep if you're unlucky.

  • SUN

    This is not related to the server reloads or the first access to Memory. Those have been ruled out. This 15-30 cpu freeze occurs at _any_ time during the execution. It can be in the very last room executed.

    Also, I don't use any built-in random name generator for my creeps. I currently name the creeps myself in [ROLE]-[TICK] format and use Spawn.canCreateCreep(). From where can you see I use one, just curious? 🙂

  • Culture

    My mistake. I looked at seancl, you all look the same 😄

    You can see the name of other players by pasting the following in the browser console.

    _.pluck(_.filter(angular.element(document.getElementsByClassName('room ng-scope')).scope().Room.objects, {type:"creep"}), "name")