<?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[Significant cpu is used before my script is run]]></title><description><![CDATA[<p>Here is an excerpt from my log with the entire contents of my script being just<br>
console.log(Game.getUsedCpu());</p>
<p>[6:29:12 AM]48.676411<br>
[6:29:13 AM]33.314896<br>
[6:29:14 AM]53.990168<br>
[6:29:16 AM]46.478472<br>
[6:29:18 AM]37.185643<br>
[6:29:19 AM]52.158025<br>
[6:29:20 AM]25.419606<br>
[6:29:22 AM]38.600426<br>
[6:29:23 AM]64.554256<br>
[6:29:24 AM]46.031705<br>
[6:29:26 AM]36.342681<br>
[6:29:27 AM]82.565116<br>
...<br>
[6:33:53 AM]106.455747</p>
<p>106? With a 100 cpu budget, that gives me -6 to execute my code.<br>
Right now it seems to average around 50 cpu used before my script is started.<br>
I deleted everything in Memory and there is no other modules other than "main" which contains the above code.</p>
<p>It's hard to do anything with approximately 50 cpu, especially when it appears the JIT needs to recompile everything every frame.</p>
<p>At the moment I have maybe 60 creep spread out over 16 rooms or so, is that related? Is it running some script to set up things (eg. Game and all the objects) and counting that as part of my cpu?</p>
<p>Despite any factors regarding server load or such, I feel like it should count the used CPU honestly.</p>]]></description><link>http://screeps.com/forum/topic/1768/significant-cpu-is-used-before-my-script-is-run</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 14:45:53 GMT</lastBuildDate><atom:link href="http://screeps.com/forum/topic/1768.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 26 May 2015 04:46:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Significant cpu is used before my script is run on Invalid Date]]></title><description><![CDATA[<p>Here is an excerpt from my log with the entire contents of my script being just<br>
console.log(Game.getUsedCpu());</p>
<p>[6:29:12 AM]48.676411<br>
[6:29:13 AM]33.314896<br>
[6:29:14 AM]53.990168<br>
[6:29:16 AM]46.478472<br>
[6:29:18 AM]37.185643<br>
[6:29:19 AM]52.158025<br>
[6:29:20 AM]25.419606<br>
[6:29:22 AM]38.600426<br>
[6:29:23 AM]64.554256<br>
[6:29:24 AM]46.031705<br>
[6:29:26 AM]36.342681<br>
[6:29:27 AM]82.565116<br>
...<br>
[6:33:53 AM]106.455747</p>
<p>106? With a 100 cpu budget, that gives me -6 to execute my code.<br>
Right now it seems to average around 50 cpu used before my script is started.<br>
I deleted everything in Memory and there is no other modules other than "main" which contains the above code.</p>
<p>It's hard to do anything with approximately 50 cpu, especially when it appears the JIT needs to recompile everything every frame.</p>
<p>At the moment I have maybe 60 creep spread out over 16 rooms or so, is that related? Is it running some script to set up things (eg. Game and all the objects) and counting that as part of my cpu?</p>
<p>Despite any factors regarding server load or such, I feel like it should count the used CPU honestly.</p>]]></description><link>http://screeps.com/forum/post/7643</link><guid isPermaLink="true">http://screeps.com/forum/post/7643</guid><dc:creator><![CDATA[tscmoo]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Significant cpu is used before my script is run on Invalid Date]]></title><description><![CDATA[<p>Just as a test, I suicided all of my creeps and it now outputs</p>
<p>[6:53:39 AM]5.816676<br>
[6:53:40 AM]3.636976<br>
[6:53:42 AM]14.490425<br>
[6:53:43 AM]25.138307<br>
[6:53:45 AM]5.462814<br>
[6:53:46 AM]6.005194<br>
[6:53:48 AM]6.023788<br>
[6:53:49 AM]4.453297<br>
[6:53:51 AM]5.006698<br>
[6:53:52 AM]4.547158<br>
[6:53:53 AM]3.560707<br>
[6:53:56 AM]7.207466</p>
<p>So that definitely helped, and reinforces my suspicion that the system runs some code to set up the Game interface and all related objects, and it counts the time used towards my used cpu. I don't know why it would take so long though, 60 creeps isn't much...<br>
Either way this is out of my control and it would be nice if it either didn't count it or it was optimized to be less significant.</p>]]></description><link>http://screeps.com/forum/post/7644</link><guid isPermaLink="true">http://screeps.com/forum/post/7644</guid><dc:creator><![CDATA[tscmoo]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Significant cpu is used before my script is run on Invalid Date]]></title><description><![CDATA[<p>fixed?</p>]]></description><link>http://screeps.com/forum/post/7645</link><guid isPermaLink="true">http://screeps.com/forum/post/7645</guid><dc:creator><![CDATA[flyingbeast]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Significant cpu is used before my script is run on Invalid Date]]></title><description><![CDATA[<p>I'm having this problem too and I think I managed to track it down. I started by putting a Game.getUsedCpu() at the top of my main.js and it almost always had a value less than 2, so the reported cpu is actually going into the execution of your scripts. </p>
<p>I have a cpu object in the global scope to keep track of cpu usage and a lot of time goes into the <code>require()</code> function it seems. I do most of my <code>require</code>'ing in a module called init, looking like this:</p>
<pre><code class="javascript">    cpu.track("init", function() {
        var modules = [
            "string", // *must* be first or catch-block will fail
            "global",
            "math",
            "protoGame",
            "protoGame",
            "protoSpawn",
            "protoCreep",
            "protoRoom",
            "protoSource",
            "protoStructure",
            "protoRoomPosition"
        ];

        _.each(modules, function(module) {
            try {
                cpu.begin(module);
                require(module)();
                cpu.end(module);
            }
            catch (ex) {
                console.log("Exception caught: {0}.Stack: {1}".format(ex, ex.stack));
            }
        });

        _.mixin(Room.prototype, brainRoom, { "chain": false });

        if (_.isUndefined(Memory.index)) {
            Memory.index = {};
        }
    });
</code></pre>
<p>The output of that looks like this (I stripped away the items that were &lt;2):<br>
```<br>
protoCreep: 10.955753000000001<br>
protoRoom: 6.102737000000001<br>
protoRoom.require: 4.112070000000003<br>
init: 27.029208</p>
<p>protoCreep: 7.1586099999999995<br>
protoRoom: 12.721302000000001<br>
protoRoom.require: 9.670390999999999<br>
init: 28.924640999999998<br>
```</p>
<p>Most of these files modify the prototypes of various game objects(hence the proto prefix) but I also timed the require calls and as you can see they take up most of the time. </p>
<p>To add some more detailed output I decided to time the execution of the modules that are actually being required by adding a begin()/end() call at the top/bottom of the those to time how long it took the VM to evaluate the actual files. The results were as follows:<br>
<code><br>
protoRoom: 5.566376000000002<br>
EnergyMap: 0.04861100000000107<br>
B-Q: 0.0905040000000028<br>
C-Q: 0.08399100000000104<br>
Statistics: 0.04209700000000183<br>
protoRoom.require: 3.4115080000000013<br>
init: 22.651317<br>
</code></p>
<p>It would be really nice if all the source files were actually pre-included before our main functions were executed so that the amount of time spent in require() calls would be reduced to a minimum. Any script file that throws a compile error is ignored. And of course, the scripts shouldn't be executed, just precompiled.</p>]]></description><link>http://screeps.com/forum/post/7646</link><guid isPermaLink="true">http://screeps.com/forum/post/7646</guid><dc:creator><![CDATA[Toolmaker]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>