Skip to content

Commit f0cd049

Browse files
authored
Fix some fine-grained cache/fswatcher problems (#4560)
In fswatcher, update the cache if mtime changes; otherwise an mtime change without an md5 change will cause the file to be rechecked every time. This was triggered in a painful way by fswatcher's cache being populated with mtimes from the cache files. Flush the fscache after an initial fine-grained upgrade, which could cause certain changes to be missed temporarily. Don't compute hashes for the whole source tree redundantly in caching mode, which saves a bunch of time on initial load.
1 parent 39c33b9 commit f0cd049

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

mypy/dmypy_server.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,9 @@ def initialize_fine_grained(self, sources: List[mypy.build.BuildSource]) -> Dict
251251
self.fscache = FileSystemCache(self.options.python_version)
252252
self.fswatcher = FileSystemWatcher(self.fscache)
253253
self.update_sources(sources)
254-
# Stores the initial state of sources as a side effect.
255-
self.fswatcher.find_changed()
254+
if not self.options.use_fine_grained_cache:
255+
# Stores the initial state of sources as a side effect.
256+
self.fswatcher.find_changed()
256257
try:
257258
# TODO: alt_lib_path
258259
result = mypy.build.build(sources=sources,
@@ -288,19 +289,26 @@ def initialize_fine_grained(self, sources: List[mypy.build.BuildSource]) -> Dict
288289
changed = self.find_changed(sources)
289290
if changed:
290291
messages = self.fine_grained_manager.update(changed)
292+
self.fscache.flush()
291293

292294
status = 1 if messages else 0
293295
self.previous_messages = messages[:]
294296
return {'out': ''.join(s + '\n' for s in messages), 'err': '', 'status': status}
295297

296298
def fine_grained_increment(self, sources: List[mypy.build.BuildSource]) -> Dict[str, Any]:
299+
t0 = time.time()
297300
self.update_sources(sources)
298301
changed = self.find_changed(sources)
302+
t1 = time.time()
299303
if not changed:
300304
# Nothing changed -- just produce the same result as before.
301305
messages = self.previous_messages
302306
else:
303307
messages = self.fine_grained_manager.update(changed)
308+
t2 = time.time()
309+
self.fine_grained_manager.manager.log(
310+
"fine-grained increment: find_changed: {:.3f}s, update: {:.3f}s".format(
311+
t1 - t0, t2 - t1))
304312
status = 1 if messages else 0
305313
self.previous_messages = messages[:]
306314
self.previous_sources = sources

mypy/fswatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def find_changed(self) -> Set[str]:
7979
# Only look for changes if size or mtime has changed as an
8080
# optimization, since calculating md5 is expensive.
8181
new_md5 = self.fs.md5(path)
82+
self._update(path)
8283
if st.st_size != old.st_size or new_md5 != old.md5:
8384
# Changed file.
8485
changed.add(path)
85-
self._update(path)
8686
return changed

0 commit comments

Comments
 (0)