changeset 44825:18e36ff8b414 stable

rust-dirstatemap: don't read the dirstate when requesting parents A future patch for issue 6303 reveals a big performance regression in the Rust `DirstateMap` that reads the entire dirstate when requesting parents instead of the first 40 bytes. `perfdiscovery` gets a *significant* speedup (from 0.101 to 0.016) when applied against said patch. I'm assuming it has other performance benefits, but this is already a good enough win. Differential Revision: https://phab.mercurial-scm.org/D8513
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 11 May 2020 16:44:11 +0200
parents f189c5280d48
children 35b255e474d9
files mercurial/dirstate.py
diffstat 1 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Thu May 14 10:24:52 2020 -0400
+++ b/mercurial/dirstate.py	Mon May 11 16:44:11 2020 +0200
@@ -1743,10 +1743,23 @@
 
         @propertycache
         def _rustmap(self):
-            self._rustmap = rustmod.DirstateMap(self._root)
+            """
+            Fills the Dirstatemap when called.
+            Use `self._inner_rustmap` if reading the dirstate is not necessary.
+            """
+            self._rustmap = self._inner_rustmap
             self.read()
             return self._rustmap
 
+        @propertycache
+        def _inner_rustmap(self):
+            """
+            Does not fill the Dirstatemap when called. This allows for
+            optimizations where only setting/getting the parents is needed.
+            """
+            self._inner_rustmap = rustmod.DirstateMap(self._root)
+            return self._inner_rustmap
+
         @property
         def copymap(self):
             return self._rustmap.copymap()
@@ -1756,6 +1769,7 @@
 
         def clear(self):
             self._rustmap.clear()
+            self._inner_rustmap.clear()
             self.setparents(nullid, nullid)
             util.clearcachedproperty(self, b"_dirs")
             util.clearcachedproperty(self, b"_alldirs")
@@ -1812,7 +1826,7 @@
                     st = b''
 
                 try:
-                    self._parents = self._rustmap.parents(st)
+                    self._parents = self._inner_rustmap.parents(st)
                 except ValueError:
                     raise error.Abort(
                         _(b'working directory state appears damaged!')