• J
    Reduce IO costs in AnalyzerFileWatcherService · a7dbaf6d
    Jason Malinowski 提交于
    This service tries to watch analyzer files to see if they've changed,
    and if they have inform the user that they'll have to restart Visual
    Studio. It did this via two ways:
    
    1. When a file was first added, it's modification time was stored in
       a dictionary, which was checked in any subsequent entry.
    2. Via file watchers.
    
    The first approach was broken in an interesting way: each time a
    reference was added, we'd add the modification time to the map (doing
    the IO to get the time). This overwrote the previous value, even if
    the value had changed in the middle. Then, we'd do the IO a second
    time, checking against the value we had just stored. As a result, the
    window where we could detect a change in the first approach was very
    tiny.
    
    I attempt to rectify what seems to be the intent here and also speed it
    up. First off, we won't overwrite previous values so the first approach
    has a better chance of actually working. Also, we'll read the data
    once instead of twice. Further more, once the file watcher (second
    approach) is active, we'll just stop reading timesetamps entirely,
    because by then there's no reason to use the first approach at all.
    
    Note this approach still has a flaw: if the file is modified between
    when we do any timestamp checking, and the file watcher is active,
    we'll completely miss the change and report nothing, at least until
    somebody tries adding the analyzer again. This isn't new; it seems
    this was already broken anyways. We could just always force the file
    watcher immediately, but that might be tied up if somebody else is using
    the service so we're still assuming IO is cheaper in that case.
    a7dbaf6d
FileChangeTracker.cs 7.3 KB