soldair/node-walkdir — pull request #6 by gjtorikian (2012-10-11 18:00:58+00:00)
Title: Make a few performance tweaks

I wanted a directory walking library that was very performant. Fortunately, I found this one !

I kept making a few tweaks along the way, because I wanted to get the search faster. I learned a lot about Node profiling and Javascript optimizations. Ultimately, I decided to gut your library and take just the parts I needed. I'm contributing back a few pieces of code that dropped my search speed down by a few hundred milliseconds.

Two other tweaks could make this library even faster:

1. Drop the event emitting when in synchronous mode. This includes doing stuff like:

```
emitter.emit('path', path, stat,depth)
...
if (options.sync) {
if(!options.no_return){
emitter.on('path',function(path,stat){
if(options.return_object) allPaths[path] = stat;
else allPaths.push(path);
});
}
}
```

A simple function call is more perfomant. Likewise, not doing the emits when in synch also makes it performant.

2. Instead of `allResults.push()`, doing `allResults += path + "\n"` is much better at providing a list of results. Possibly because push always takes `n` amount of time?

I realize both of these pertain to improving the sync speed, but that's because I was concerned with an organized directory search.