Patchwork [remotenames-ext] remotenames: lazily read remotenames file

login
register
mail settings
Submitter Stanislau Hlebik
Date Jan. 6, 2017, 3:44 p.m.
Message ID <043090278718e0b82f6b.1483717485@devvm1840.lla2.facebook.com>
Download mbox | patch
Permalink /patch/18123/
State Accepted
Headers show

Comments

Stanislau Hlebik - Jan. 6, 2017, 3:44 p.m.
# HG changeset patch
# User Stanislau Hlebik <stash@fb.com>
# Date 1483717320 28800
#      Fri Jan 06 07:42:00 2017 -0800
# Node ID 043090278718e0b82f6b3d8f7258d56080209d40
# Parent  c65e41aef8dc18f29f8652f9d71a9c0d028fd95d
remotenames: lazily read remotenames file

remotenames file is read every time even if it's not needed. That wastes up
to 100 ms on every call. Let's read it lazily instead.
Sean Farley - Jan. 6, 2017, 6:36 p.m.
Stanislau Hlebik <stash@fb.com> writes:

> # HG changeset patch
> # User Stanislau Hlebik <stash@fb.com>
> # Date 1483717320 28800
> #      Fri Jan 06 07:42:00 2017 -0800
> # Node ID 043090278718e0b82f6b3d8f7258d56080209d40
> # Parent  c65e41aef8dc18f29f8652f9d71a9c0d028fd95d
> remotenames: lazily read remotenames file
>
> remotenames file is read every time even if it's not needed. That wastes up
> to 100 ms on every call. Let's read it lazily instead.

Huh, I thought this was already done. Queued this one asap, thanks!

Patch

diff --git a/remotenames.py b/remotenames.py
--- a/remotenames.py
+++ b/remotenames.py
@@ -282,7 +282,7 @@ 
     """Read-only dict-like Class to lazily resolve remotename entries
 
     We are doing that because remotenames startup was slow.
-    We read the remotenames file once to figure out the potential entries
+    We lazily read the remotenames file once to figure out the potential entries
     and store them in self.potentialentries. Then when asked to resolve an
     entry, if it is not in self.potentialentries, then it isn't there, if it
     is in self.potentialentries we resolve it and store the result in
@@ -293,10 +293,11 @@ 
         self.potentialentries = {}
         self._kind = kind # bookmarks or branches
         self._repo = repo
-        self._load()
+        self.loaded = False
 
     def _load(self):
         """Read the remotenames file, store entries matching selected kind"""
+        self.loaded = True
         repo = self._repo
         alias_default = repo.ui.configbool('remotenames', 'alias.default')
         for node, nametype, remote, rname in readremotenames(repo):
@@ -328,6 +329,8 @@ 
         return [binnode]
 
     def __getitem__(self, key):
+        if not self.loaded:
+            self._load()
         val = self._fetchandcache(key)
         if val is not None:
             return val
@@ -345,6 +348,8 @@ 
             return None
 
     def keys(self):
+        if not self.loaded:
+            self._load()
         for u in self.potentialentries.keys():
             self._fetchandcache(u)
         return self.cache.keys()