Navigation

    forum

    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    1. Home
    2. Hatyr
    3. Posts
    • Flag Profile
    • block_user
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Groups
    • Blog

    Posts made by Hatyr

    • RE: I made a thing.

      ^^ I've just updated it to allow for registering of any functions that you want.  Useful to those that don't utilize the global prototypes the same way that I do.

      posted in General Discussion
      Hatyr
    • Fix require times.

      I've been doing a lot of work to bring down my CPU usage, but I can't seem to catch a break from the time it takes to load up my script.  I've been getting a wide range of CPU limit notifications (anywhere from 0 to thousands of notifications per hour).

      After putting in a ton of time optimizing my script, and working with my profiler, I don't know that there is anything I can do.

      Below is my current main.js.

      require('perf');
      require('creep');
      require('source');
      require('spawns');
      require('structures');
      require('room-position');
      var profiler = require('profiler');

      profiler.enable();
      module.exports.loop = function() {
      profiler.wrap(function() {
      var start = Game.getUsedCpu();
      var index = 0;
      for (var roomName in Game.rooms) {
      index++;
      if (index === 1 || Game.cpuLimit > 60) {
      Game.rooms[roomName].work();
      }
      }
      console.log(Game.getUsedCpu() - start, start);
      });
      }
      Here is the output that I then see in the console (times on the left are the times that my main loop ran in, time on the right is the start variable).  There are a lot more lines than this, but that's all that fits in the console.
       
      [3:01:31 AM] 14.490700999999994 25.062711
      [3:01:33 AM] 8.401745000000002 17.992238
      [3:01:36 AM] 17.664528999999998 30.933001
      [3:01:38 AM] 18.328616000000004 33.14149
      [3:01:39 AM] 5.719020000000002 10.325317
      [3:01:43 AM] 15.669170000000001 47.227466
      [3:01:44 AM] 9.323974 17.043523
      [3:01:48 AM] 5.914033999999999 9.580664
      [3:01:54 AM] 5.575247000000001 17.763152
      [3:01:55 AM] 8.342134000000001 18.901647
      [3:01:59 AM] 6.6542780000000015 21.621283
      [3:02:01 AM] 8.344047 17.63203
      [3:02:04 AM] 13.660488 25.990941
      [3:02:07 AM] 8.154161000000002 18.013329
      [3:02:09 AM] 13.498067000000006 43.098558
      [3:02:10 AM] 25.970536000000003 17.839734
      [3:02:14 AM] 8.042030999999998 23.107959
      [3:02:16 AM] 7.167925 9.173901
      [3:02:21 AM] 17.976727999999994 27.388998
      [3:02:22 AM] 4.847477999999999 9.226024
      [3:02:25 AM] 13.988324000000002 31.106472
      [3:02:28 AM] 13.301356000000002 19.72084
      [3:02:29 AM] 13.865193999999999 17.980405
      [3:02:32 AM] 12.265623999999999 29.939694
      [3:02:35 AM] 9.779004999999998 55.085228
      [3:02:38 AM] 5.709491 26.645434
      [3:02:39 AM] 5.808555000000002 16.596426
      [3:02:43 AM] 8.617096 18.15661
      [3:02:46 AM] 13.436439 23.091488
      [3:02:48 AM] 20.112817 34.604358
      [3:02:54 AM] 10.348903 17.545147
      [3:02:56 AM] 12.349533999999998 19.725963
      [3:02:59 AM] 12.894641999999997 20.269176
      [3:03:01 AM] 8.228573 17.514257
      [3:03:03 AM] 6.326778999999998 16.346291
      [3:03:06 AM] 13.272701999999995 43.243217
      [3:03:08 AM] 10.555196000000002 17.013294
      [3:03:11 AM] 5.294263000000001 17.063165
      [3:03:12 AM] 4.918824000000001 16.808634
      [3:03:16 AM] 14.891358000000002 10.968451
      [3:03:17 AM] 7.155049000000002 17.082047
      [3:03:19 AM] 7.033011000000002 17.609693
      [3:03:23 AM] 22.316795 31.506726
      [3:03:27 AM] 10.088149999999999 34.022269
      [3:03:28 AM] 11.699035 10.553996
      [3:03:32 AM] 8.241211 17.3698
      [3:03:34 AM] 5.379438000000004 18.126723
      [3:03:36 AM] 8.234374999999996 26.21249
      [3:03:38 AM] 6.508486999999999 16.800408
      posted in Feature Requests
      Hatyr
    • RE: Profiling

      Piggy backing on this, I just released my profiler as OS. https://github.com/gdborton/screeps-profiler

      posted in General Discussion
      Hatyr
    • RE: Best performance practice while using modules

      I've found that each require call takes an amount of time correlated to how much the file contains...  Following neomatrix's testing I created a bundle containing all my code then measured it's require time in main.js... 23 ms.

      posted in General Discussion
      Hatyr
    • RE: High CPU usage differences on a tiny script

      Delete is a fairly expensive operation, but I think the spikes are probably from require statements.  Currently there doesn't seem to be a way around this, as in-lining all the code also makes the CPU spike.

      The only solace is that when using `module.exports.loop` your require statements aren't always run.

      posted in Technical Issues and Bugs
      Hatyr
    • RE: Inconsistencies in Memory Loading

      I'm running into this now too...

      posted in Technical Issues and Bugs
      Hatyr
    • RE: Need help with this code for performance issue

      I'm sure you've figured this out by now, but moving takes a static .2 CPU time (the .3 is a little concerning).  The larger 13 is probably due to pathfinding.  As the previous poster said you could either roll your own path finder (although I believe it is faster now), or cache the results somehow.

      posted in Help
      Hatyr
    • RE: Now you can play Screeps without writing a single line of code!

      @dexnode it isn't pointless... the downside to scripting is that your script can have flaws or situations that you didn't expect.  If you're at your computer you can adjust for some minor flaws in your or someone else's script.

      posted in General Discussion
      Hatyr
    • I made a thing.

      I just open sourced a profiler that I made for Screeps to help keep my CPU usage lower.  Hopefully I'm not the only one who will find it useful.

      https://github.com/gdborton/screeps-profiler

      posted in General Discussion
      Hatyr