<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[isActive() call extremely expensive.]]></title><description><![CDATA[<p>Structure.isActive() is extremely expensive due to the inefficient implementation, so one has stopped using it. The effect is extremely pronounced in a room with a lot of rampart structures present.
One believes, that the same algorithm is used in the server side for determining the active structures and refactoring the code responsible for determining the active structures vs the controller level, would give a significant boost to the servers' performance.</p>
<p>ta</p>
]]></description><link>http://screeps.com/forum/topic/3087/isactive-call-extremely-expensive</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 00:28:55 GMT</lastBuildDate><atom:link href="http://screeps.com/forum/topic/3087.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 21 Oct 2020 14:55:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to isActive() call extremely expensive. on Invalid Date]]></title><description><![CDATA[<p>Structure.isActive() is extremely expensive due to the inefficient implementation, so one has stopped using it. The effect is extremely pronounced in a room with a lot of rampart structures present.
One believes, that the same algorithm is used in the server side for determining the active structures and refactoring the code responsible for determining the active structures vs the controller level, would give a significant boost to the servers' performance.</p>
<p>ta</p>
]]></description><link>http://screeps.com/forum/post/15683</link><guid isPermaLink="true">http://screeps.com/forum/post/15683</guid><dc:creator><![CDATA[AdeptOfNone]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to isActive() call extremely expensive. on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/2699">@adeptofnone</a> Move to Techincal Issues &amp; Bugs
kthx bye</p>
]]></description><link>http://screeps.com/forum/post/15685</link><guid isPermaLink="true">http://screeps.com/forum/post/15685</guid><dc:creator><![CDATA[AdeptOfNone]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to isActive() call extremely expensive. on Invalid Date]]></title><description><![CDATA[<p><a href="https://screeps.com/forum/topic/2963/optimization-for-checkstructureagainstcontroller" rel="nofollow">https://screeps.com/forum/topic/2963/optimization-for-checkstructureagainstcontroller</a></p>
]]></description><link>http://screeps.com/forum/post/15686</link><guid isPermaLink="true">http://screeps.com/forum/post/15686</guid><dc:creator><![CDATA[Tigga]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to isActive() call extremely expensive. on Sun, 22 Nov 2020 18:51:56 GMT]]></title><description><![CDATA[<p>Have you tried caching it? Here is my code on how I cached it.</p>
<pre><code>//cache the isActive() function.. This requires all structures to have memory
//see https://stackoverflow.com/questions/30147800/extend-source-prototype-to-have-a-memory-object for an example

Object.defineProperty(OwnedStructure.prototype, 'IsActive', { 
	get: function() {
	    if (!this.my) return false //out ours
	    if (!this.memory.active) this.memory.active = this.isActive() //initialize
	    return this.memory.active
	},
	configurable: true,
});

//determine if we need to refresh the isActive() cache on an RCL downgrade
Room.prototype.ActiveBuildingCache = function() {
    //level didn't change
    if (this.memory.currentlevel === this.controller.level) return true
    
    //We increased the RCL. Therefore, everything should be the same
    if (this.memory.currentlevel &lt; this.controller.level) {
        this.memory.currentlevel = this.controller.level //set to new RCL
    } else {
        //decreased level.. Need to recalc what is active and what isn't
        this.memory.currentlevel = this.controller.level //set the new RCL
        const mystructures = this.find(FIND_MY_STRUCTURES) //get all structures
        
        for (let s of mystructures) delete s.memory.active //delete the active flag
    }
    
    return true
}
</code></pre>
]]></description><link>http://screeps.com/forum/post/15761</link><guid isPermaLink="true">http://screeps.com/forum/post/15761</guid><dc:creator><![CDATA[CrAzYDubC]]></dc:creator><pubDate>Sun, 22 Nov 2020 18:51:56 GMT</pubDate></item><item><title><![CDATA[Reply to isActive() call extremely expensive. on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/4837">@crazydubc</a> the engine does its own active check in a call when you use the structure</p>
]]></description><link>http://screeps.com/forum/post/15773</link><guid isPermaLink="true">http://screeps.com/forum/post/15773</guid><dc:creator><![CDATA[cribbit]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to isActive() call extremely expensive. on Invalid Date]]></title><description><![CDATA[<p>The engine code actually very rarely to never calls the structure isActive method, it's hard coded to check against controller and does a very, very expensive partition operation every time it's callled. It's also however not easy to fix, as the ideal would be to calculate and cache this information whenever RCL changed or a structure was placed/destroyed.</p>
]]></description><link>http://screeps.com/forum/post/15774</link><guid isPermaLink="true">http://screeps.com/forum/post/15774</guid><dc:creator><![CDATA[WarInternal]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to isActive() call extremely expensive. on Invalid Date]]></title><description><![CDATA[<p>This was meant for end users who are utilizing the isActive() call. Not server side.</p>
]]></description><link>http://screeps.com/forum/post/15787</link><guid isPermaLink="true">http://screeps.com/forum/post/15787</guid><dc:creator><![CDATA[CrAzYDubC]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>