jrburke/r.js — Issue #50: Copying large directories uses lots of memory
Author: jrburke
Created: 2011-12-02 20:40:37+00:00
State: open

@timmywil found that doing a build with an appDir: that had about 450mb of files in it ended up using 600mb before doing the actual dependency tracing.

So there seems to a be a weakness in the [copyDir code for node](https://github.com/jrburke/r.js/blob/master/build/jslib/node/file.js), which does sync file copying via binary writes. This was done because of the ease of dealing with sync file code, but probably need to switch to:

* Use streams instead of sync file IO via writeFileSync
* Or, maybe doing a process.nextTick() to break up the work, allow garbage collector to run?

That second one is a bit hacky, and since it would imply needing a callback into file.copyDir, might as well try the stream approach.