ForbesLindesay / browserify-middleware

express middleware for browserify, done right
http://browserify.org
MIT License
381 stars 66 forks source link

Implement dynamic caching #10

Closed ForbesLindesay closed 11 years ago

ForbesLindesay commented 11 years ago

This adds a new cache option of 'dynamic' which is now the default for development. It speeds compilation by caching the parsed versions of each file and only updating them when the last modified times have changed.

Unlike most methods for doing this, it does not use a watch on the files, instead it polls all the files whenever a request is made in order to check the files are up to date. On my computer this takes about 10ms per request for a fairly large number of files, so seems to be acceptably quick. For applications that include large files like jQuery it can provide a 4 times speed up once the files have been cached.

If nobody has any issues with this by 2013-07-04T18:00:00Z I will merge this and release as v1.14.0. If someone else code reviews it and gives it the all clear, I will release it straight away.

jordwalke commented 11 years ago

@ForbesLindesay: I cannot wait to try this out tonight!

jordwalke commented 11 years ago

I just tried this out, but I'm having a hard time getting browserify-middleware to recognize when the files have changed. I'm applying a transform as an option. Could that be effecting the detection of changes?

jordwalke commented 11 years ago

Sorry to alarm, I believe I was incorrectly linking the local npm module. I have a very large library that seldom changes and a small app that changes frequently.

When absolutely nothing has changed, I see a decrease in request time (for that packaged file) of approximately 60%. (From 450ms to 150ms). That's a nice win! (Especially when I want to reload the page several times to test something).

When something actually does change in the small app file (not the huge lib), I see a decrease from 420ms to 320ms (approximately 25%).