npm-shrinkwrap could shrink better

Unlike most of our team’s developers, who already got the latest mac pro (quite high end), my poor old thing doesn’t have any SSD, and a bit shy with its limited RAM & CPU got me a bit unhappy.

Coz we’re creating larger app using node, more & more modules are to be loaded each time, and npm install just took so long, even with cache for me. Obviously, file system’s caching doesn’t serve my best interest as it’s an HDD. 1.4k modules did seem too many, and even worse, quite a few binary modules there, node-expat for example, requires gyp builds repeatedly, so did msgpack, usage … etc. Anyway, I couldn’t bear with it further, and turned to shrinkwrap for help.

But it doesn’t truely shrink, not much at least, u get a manifest which install did, common dependencies up in the ancestors were properly cached, and leveraged by descendants in the deps tree, but when they got scattered in different branches, no luck there. And that’s not what i liked, so i tried optimizing the shrinkwrap, well, complying with the npm’s dependency resolution attempts, i just need to merge common dependencies from different branches to their common ancestor, place it there, and it should work.

so it does:, a quick summary, i got a 7k shrinkwrap.json down to 1.2k lines of code, and reduced modules from 1.4k to 200+. my app install becomes so fast, that an HDD didn’t feel that bad any more, which is great, coz our datacenter still uses HDD last time i checked. Even better, my application loads in 1s instead of 4s thanks to less modules to be loaded. i hoped that the app runtime could better too, but that didn’t happen according to my jmeter test, and is probably right since modules got loaded, not much differences thereafter.

still, it’s a prettier picture, no runtime performance penalty at all, application starts much faster, install spins much faster. only downside i saw, it breaks some anticipation where ur dependencies modules ought to be, but given global install & npm cache, u probably cannot make such assumption either.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s