Bug 1355630 - Use a set for membership testing; r?chmanchester draft
authorGregory Szorc <gps@mozilla.com>
Tue, 11 Apr 2017 15:25:13 -0700
changeset 560842 58739c053019a4dc56cfb4e4255fa89bcaeae2c0
parent 560841 2bc1e12ecbea89284ea9f6e1be840d815c22458a
child 560843 bd68e0bdb017b7e3d64a0b83441488e120c641a8
child 561605 004466bd4b9a25151b73d9e52cfe00ec43a94c7e
push id53552
push userbmo:gps@mozilla.com
push dateTue, 11 Apr 2017 23:50:02 +0000
reviewerschmanchester
bugs1355630
milestone55.0a1
Bug 1355630 - Use a set for membership testing; r?chmanchester With ~42,000 entries in relpaths, this change drops execution time of this loop from ~23s to ~0.01s. MozReview-Commit-ID: Afm245tjWUQ
python/mozbuild/mozbuild/frontend/mach_commands.py
--- a/python/mozbuild/mozbuild/frontend/mach_commands.py
+++ b/python/mozbuild/mozbuild/frontend/mach_commands.py
@@ -266,24 +266,29 @@ class MozbuildFileCommands(MachCommandBa
         finder = FileFinder(self.topsrcdir)
         if repo:
             reader_finder = MercurialRevisionFinder(repo, rev=rev,
                                                     recognize_repo_paths=True)
         else:
             reader_finder = default_finder
 
         # Expand wildcards.
+        # One variable is for ordering. The other for membership tests.
+        # (Membership testing on a list can be slow.)
         allpaths = []
+        all_paths_set = set()
         for p in relpaths:
             if '*' not in p:
-                if p not in allpaths:
+                if p not in all_paths_set:
+                    all_paths_set.add(p)
                     allpaths.append(p)
                 continue
 
             if repo:
                 raise InvalidPathException('cannot use wildcard in version control mode')
 
             for path, f in finder.find(p):
-                if path not in allpaths:
+                if path not in all_paths_set:
+                    all_paths_set.add(path)
                     allpaths.append(path)
 
         reader = self._get_reader(finder=reader_finder)
         return reader.files_info(allpaths)