CPU Usage



  • What determines CPU usage? Is it only documented functions using the API, meanings its strictly a game mechanic? Or is it more realistic in that large amounts of, for example, if statements can eventually consume CPU?

    What does CONST CPU usage mean? I'd assume that it uses some O(1) mechanic where as others use O(n) or something similar that scales to something. But since we don't necessarily know what, it's seemingly difficult to optimize. In addition, an O(1) operation can still be a heavy operation... 

    Any insight would be great. 


  • Culture

    Everything takes CPU. If you were to create a function that called zero of the game functions but always took approximately 20ms, then it will cost about 20cpu.

    CONST functions cost a constant 0.2 cpu when called. That's because these functions schedule actions that occur during the "execution" phase of the game, and those actions themselves take up time. For example, adding a flag is going to result in a database call, which will put load on the servers that your script isn't going to see. So the CONST functions take that into account.

    Another really important feature is your bucket. You store unused CPU (CPULIMIT - CPUUSED) in your bucket, and it gets used when you go over your limit. This allows you do do things like multiroom path finding.


  • Dev Team