require occasionally takes up a lot of CPU



  • Occasionally this section of the code ( beginning of my main module ) takes up more then 50 cpu cycles ( I saw it as high as 70!) which coupled with some other strange functions taking a long time ends up pushing CPU over the limit.

    var _ = require('lodash');
    
    global.rolesModule = require('roles');
    global.spawner = require('spawner');
    global.enemywatch = require('enemywatch');
    global.finder = require('finder');
    
    global.perf = require('profiler');
    


  • Well, that depends entirely on what you are requiring... so nobody can give a useful statement on that behalf.

    Just FYI, you don't need to require lodash, _ is already present as global property.



  • I have noticed this behavior as well and I think it is because of the javascript files being compiled, as I detailed in my answer in this post