gmethvin / directory-watcher

A cross-platform Java recursive directory watcher, with a JNA macOS watcher and Scala better-files integration
Apache License 2.0
263 stars 34 forks source link

Prefer file events over directory events in OSX watch service? #22

Open jvican opened 5 years ago

jvican commented 5 years ago

I was having a look at the Carbon file event API and the current implementation of the OSX's watch service. I realized that the events that Carbon notifies us about are at the directory level, and hence in our callback implementation we're iterating on all the files present in that directory at once and finding the ones that were created/modified/deleted.

The main issue with this implementation is performance. It seems we could improve it by enabling events at the file level with the following flag https://developer.apple.com/documentation/coreservices/1455376-fseventstreamcreateflags/kfseventstreamcreateflagfileevents?language=objc. This way, we don't need to list all the recursive files in every event that we receive every time we get a directory event every 500 ms (the default latency).

gmethvin commented 5 years ago

I think it's worth a try. If we do try it, we should make sure we test performance with making large changes to directory structures, as that could lead to a lot of events being generated.

jvican commented 5 years ago

Yes, that's something we must test. I'm not in a rush to implement this, so if somebody else wants to give a try before me, go ahead. Realistically speaking, I don't have time for this in the next 4 months.