Fix false positives when using watch flag. #191
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The watch flag is an awesome feature! However, I noticed one small issue when I watched what was going on closely. There were some false positives triggering a rebuild when it wasn't necessary.
Here's a demo in which I save the file once but two rebuilds are triggered. One immediately, then another about a second later:
I have used fsnotify before to watch for changes, so I had a hunch for where to look. I found two cases which were causing false positives:
I can understand if you have some hesitation about keeping a large number of hashes of files, but in practice, I haven't noticed any impact on performance. I used xxhash which is pretty fast. That being said, it's possible the code could be optimized a bit more. For example, here I'm using ioutil to read the entire source file so I can calculate the hash. If you are already reading the source file somewhere, it might make sense to calculate the hash at that point instead of reading the whole file twice. However, I couldn't find a more appropriate place to put it at first glance.