Unexplained Cpu Usage which is independent from Code



  • Starting today i noticed a high CPU-usage in classes which have never been using that much. I started disabling those classes but the CPU-usage just went on to the next function like f.e.:

    The workload went from GarbageCollector -> Initialize -> EventManager -> Tower -> Creeps -> Spawner -> Architect.

    And as soon as i disabled all this classes it disappeared. As my code does not run in threads, it seems like the workload appears at a fixed time and does not occure if my code has been executed too fast.

    I added an example below. There are no dependencies between those classes and initialize does nothing at all as it is only run on developing a new room.

    Someone got an idea? Would be awesome!

     

     

     



  • It's most likely the Memory parse cost.  The first time you access memory, you incur the cost of unpacking the whole thing.

    Try adding another 2 lines at the top:

     

    console.log('before memory', Game.cpu.getUsed());

    Memory; // This will force the Memory to de-serialize and be read into the cache for use during the tick

    <rest of your code here>