duojs / duo

A next-generation package manager for the front-end
3.42k stars 117 forks source link

move requires from bin/_duo so commands execute faster #63

Open lancejpollard opened 10 years ago

lancejpollard commented 10 years ago

Just logged before and after the require statements in bin/_duo and it takes a while for those things to load up, maybe 100-500ms, so it takes a half a second or more to execute the command.

#!/usr/bin/env node

/**
 * Module dependencies.
 */

var write = require('fs').createWriteStream;
var Command = require('commander').Command;
var resolve = require('path').resolve;
var exists = require('fs').existsSync;
var mkdirp = require('mkdirp').sync;
var Logger = require('stream-log');
var stat = require('fs').statSync;
var spawn = require('win-fork');
var pkg = require('../package');
var path = require('path');
var fs = require('co-fs');
var Duo = require('..');
var co = require('co');

Ideally it would immediately execute the command and give you feedback similar to how component does it now :)

matthewmueller commented 10 years ago

Oh interesting, so basically requiring the minimum number of modules up front before logging? i'm +1 to that idea.

lancejpollard commented 10 years ago

Awesome, yep that's it pretty much.

dominicbarnes commented 10 years ago

+1

yields commented 10 years ago

i'de like to keep requires up top, but wow 500ms is a lot, here are the slowest modules that we load.

screen shot 2014-06-13 at 1 49 22 pm

removing / using alternatives should speed things up.

matthewmueller commented 10 years ago

yah, let's get rid of pretty-error.. doesn't work on light terminals anyway.

matthewmueller commented 10 years ago

I think we need to go back and figure this one out, loading duo is too slow right now.

@yields what program did you use to analyze require load time?

kevva commented 10 years ago

https://www.npmjs.org/package/time-require

kevva commented 10 years ago

From lib/duo.js:

screenshot from 2014-10-27 08 45 57

matthewmueller commented 10 years ago

ah cool, thanks @kevva. wow that's ridiculous. I think duo-package (with request) is the culprit, but it seems like it's not getting cached, maybe it's loading 2 separate duo-package versions.

kevva commented 10 years ago

I've started to just requiring request on demand whenever I use it. So huge. Seems to speed up duo-package by ~400ms.

screenshot from 2014-10-27 19 04 28