How to determine CPU usage
-
I just recently started playing screeps and now I am running into the problem of CPU limit. I expanded to a second room and now the CPU sometimes hits over 30, even 40 per tick. Probably there are a lot more creeps to process being around ~30 Creeps in total. What I understand is that pathfinding and maybe also filtering use a lot of CPU. Probably that's quite high CPU cost filtering multiple times through all the creeps to determine which Creep lives in which room... and so on. Does anybody have a solution how to identify where a high CPU usage actually comes from, so I can improve the code.
-
There is some help on discord #cpu-clinic. A link from there is:
https://github.com/bonzaiferroni/screepswiki/wiki/%23cpu-clinic-faq#javascript-performance-links
The mentioned profiler can help to identify where your cpu goes:
-
So I ran the profiler and I find the result quite interesting. Most of the CPU usage is indeed pathfinding and
creep.moveTo()
. Seems I will start working on caching paths in memory now. Thanks for the help!