Subject: bug#44638: [PATCH 1/2] autorevert: don't reuse existing watch descriptors

From: Spencer Baugh <[email-masked]>
Date: Mon, 30 Nov 2020 13:01:43 -0500

Spencer Baugh <[email-masked]> writes:
> Eli Zaretskii <[email-masked]> writes:
>> Again, we watch the directory of the file, so what inotify does with
>> files is not really relevant, IMO.  I wonder what that means for the
>> changes you propose.
>
> Ah. Well, the inotify comment was just an example. Even given that Emacs
> watches directories rather than files, I think this change is for the
> best - the overhead of registering 5 files directly instead of 1
> underlying directory is minimal.

So does this kind of change still seem plausible?  Again, the overhead
of additional watches for the same file in the operating system is
minimal, and is rare anyway.

The alternative to this change is to add a new hash table to autorevert
which maps filenames to file-notify watches, so that autorevert can look
up duplicate watches efficiently in O(1) instead of iterating over all
watches in O(n) as it does now.

I started doing that originally, but concluded it was unnecessary since
sharing watches is unnecessary.  But it's a much smaller change to
behavior while still getting the same performance gain, so if you'd
prefer that, I can do it.