CPU tips and tricks



  • Hello! I was just wondering if anyone has any suggestions on how to save on CPU... I am already reusing creep paths as much as I can, but It seems like no matter what I try, I always have the same error:

    Script execution has been terminated: CPU bucket is empty

    Thanks 😄



  • The biggest saving i found was by replacing Structure.prototype.isActive

        const _isActive = Structure.prototype.isActive;
        Structure.prototype.isActive = function() {
            if (this.structureType === STRUCTURE_CONTAINER || this.structureType === STRUCTURE_ROAD) {
                // Always true for these
                this.isActive = function() { return true };
                return true;
            }
            const room = this.room;
            const roomLevel = (room.memory.level || room.controller.level);
            if (roomLevel === CONTROLLER_MAX_LEVEL) {
                this.isActive = function() { return true };
                return true;
            }
            const curActive = _isActive.call(this);
            this.isActive = function() { return curActive };
            return curActive;
        };
    


  • Enlarge the harvesters by more WORK parts will save a lot CPU.