From c83749311f6009fd67570a95497f6fd150442c01 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Mon, 11 Mar 2019 12:26:53 -0400 Subject: [PATCH] Avoid some function dispatch overhead Also, we might avoid some dict lookup overhead by being optimistic about finding the entry. At worst, we do two lookups - which is just what we did before. --- src/allmydata/frontends/magic_folder.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/allmydata/frontends/magic_folder.py b/src/allmydata/frontends/magic_folder.py index db0ed3961..2ddc18113 100644 --- a/src/allmydata/frontends/magic_folder.py +++ b/src/allmydata/frontends/magic_folder.py @@ -1869,9 +1869,17 @@ class Downloader(QueueMixin, WriteFileMixin): local_dbentry.version < remote_version or (local_dbentry.version == remote_version and local_dbentry.last_downloaded_uri != remote_uri)): ADD_TO_DOWNLOAD_QUEUE.log(relpath=relpath_u) - if scan_batch.has_key(relpath_u): + + # The scan_batch is shared across the scan of multiple + # DMDs. It is expected the DMDs will most often be mostly + # synchronized with each other. The common case, then, is + # that there is already an entry for relpath_u. So try to + # make that the fast path: assume there is a value already + # and extend it. If there's not, we'll do an extra lookup + # to initialize it. + try: scan_batch[relpath_u] += [(file_node, metadata)] - else: + except KeyError: scan_batch[relpath_u] = [(file_node, metadata)] self._status_reporter( True, 'Magic folder is working',