changeset 6730:6fb68819e58e

git: improve performance working with git changesets GitRepository._repo instantiates a new dulwich.repo.Repo on every usage, rather than once at initialization time of GitRepository. As this involves a lot of filesystem access, this is a costly operation. Instead, let GitRepository.__init__ instantiate a dulwich.repo.Repo once, and let GitRepository._repo just return it. This improves performance significantly. On test_graphmod_git, performance improves from 6.29 seconds median to 3.06 seconds median. [Thomas De Schampheleire: extend improvement to _all_ usage of GitRepository._repo instead of only some. To limit the delta, retain the _repo property but simply return self.repo.]
author Eivind Tagseth <eivindt@gmail.com>
date Sat, 01 Jul 2017 21:47:30 +0200
parents 043621a79cdb
children ab5c736930cb
files kallithea/lib/vcs/backends/git/repository.py
diffstat 1 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/vcs/backends/git/repository.py	Sat Jul 01 22:39:41 2017 +0200
+++ b/kallithea/lib/vcs/backends/git/repository.py	Sat Jul 01 21:47:30 2017 +0200
@@ -59,8 +59,8 @@
                  update_after_clone=False, bare=False):
 
         self.path = safe_unicode(abspath(repo_path))
-        repo = self._get_repo(create, src_url, update_after_clone, bare)
-        self.bare = repo.bare
+        self.repo = self._get_repo(create, src_url, update_after_clone, bare)
+        self.bare = self.repo.bare
 
     @property
     def _config_files(self):
@@ -72,7 +72,7 @@
 
     @property
     def _repo(self):
-        return Repo(self.path)
+        return self.repo
 
     @property
     def head(self):
@@ -239,7 +239,7 @@
                 else:
                     return Repo.init(self.path)
             else:
-                return self._repo
+                return Repo(self.path)
         except (NotGitRepository, OSError) as err:
             raise RepositoryError(err)