shama / gaze

:crystal_ball: A globbing fs.watch wrapper built from the best parts of other fine watch libs.
MIT License
1.16k stars 167 forks source link

Non linear start-up time for large folders #222

Open chebum opened 8 years ago

chebum commented 8 years ago

Hi,

startup.js test suite on my machine shows that startup time increases non-linearly. For 100 items per folder it's 1.5ms per file, while for 1000 items it's 7ms per file. I found two problems helper.objectPush method.

  1. When adding an array of items, the method does concatenation and allocates new array. Then again a new array is allocated inside the helper.unique method.
  2. Calling helper.unique method isn't necessary when adding a single item into the array. It's enough to call indexOf to check that the val doesn't exist in the current array.

Changes above greatly improves performance on my machine. Actually per file time reduces with growing number of files per directory.

I'll submit a PR in a minute. If the suggestions above make sense, please accept it.

Thanks,

chebum commented 8 years ago

As long as this repo seems to be abandoned, take a look at this fork: https://github.com/chebum/gaze It contains a fix and use instructions.

shama commented 8 years ago

If you want to send a PR for it, the patch looks good to me. Thanks!

chebum commented 8 years ago

@shama My fix conflicts with a test mentioned in #214. I believe the test is wrong. Could you please check if I'm correct or not?