Rev 2495: Save approx 30-60ms (5-10%) on a LP tree by not calling time.time() for every entry. in http://bzr.arbash-meinel.com/branches/bzr/experimental/dirstate-nohc

John Arbash Meinel john at arbash-meinel.com
Fri Mar 2 01:38:13 GMT 2007


At http://bzr.arbash-meinel.com/branches/bzr/experimental/dirstate-nohc

------------------------------------------------------------
revno: 2495
revision-id: john at arbash-meinel.com-20070302013806-q40tsj7ohnfz9vj0
parent: john at arbash-meinel.com-20070302012753-5jwb15csi4j2mi4w
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dirstate-nohc
timestamp: Thu 2007-03-01 19:38:06 -0600
message:
  Save approx 30-60ms (5-10%) on a LP tree by not calling time.time() for every entry.
modified:
  bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
  bzrlib/tests/test_dirstate.py  test_dirstate.py-20060728012006-d6mvoihjb3je9peu-2
-------------- next part --------------
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py	2007-03-02 01:27:53 +0000
+++ b/bzrlib/dirstate.py	2007-03-02 01:38:06 +0000
@@ -290,6 +290,7 @@
         self._lock_state = None
         self._id_index = None
         self._end_of_header = None
+        self._cutoff_time = None
         self._split_path_cache = {}
         self._bisect_page_size = DirState.BISECT_PAGE_SIZE
 
@@ -1062,9 +1063,11 @@
             if minikind == 'd':
                 return None
 
-            cutoff = self._sha_cutoff_time()
-            if (stat_value.st_mtime < cutoff
-                and stat_value.st_ctime < cutoff):
+            if self._cutoff_time is None:
+                self._sha_cutoff_time()
+
+            if (stat_value.st_mtime < self._cutoff_time
+                and stat_value.st_ctime < self._cutoff_time):
                 # Return the existing fingerprint
                 return saved_link_or_sha1
 
@@ -1101,11 +1104,12 @@
         Files modified more recently than this time are at risk of being
         undetectably modified and so can't be cached.
         """
-        # TODO: jam 20070301 Cache the cutoff time as long as we hold a lock.
-        #       time.time() isn't super expensive (approx 3.38us), but
-        #       when you call it 50,000 times it adds up.
-        #       For comparison, os.lstat() costs 7.2us if it is hot.
-        return int(time.time()) - 3
+        # Cache the cutoff time as long as we hold a lock.
+        # time.time() isn't super expensive (approx 3.38us), but
+        # when you call it 50,000 times it adds up.
+        # For comparison, os.lstat() costs 7.2us if it is hot.
+        self._cutoff_time = int(time.time()) - 3
+        return self._cutoff_time
 
     def _lstat(self, abspath, entry):
         """Return the os.lstat value for this path."""
@@ -2126,6 +2130,10 @@
         self._parents = []
         self._ghosts = []
         self._dirblocks = []
+        self._id_index = None
+        self._end_of_header = None
+        self._cutoff_time = None
+        self._split_path_cache = {}
 
     def lock_read(self):
         """Acquire a read lock on the dirstate"""

=== modified file 'bzrlib/tests/test_dirstate.py'
--- a/bzrlib/tests/test_dirstate.py	2007-03-02 01:27:53 +0000
+++ b/bzrlib/tests/test_dirstate.py	2007-03-02 01:38:06 +0000
@@ -1015,7 +1015,7 @@
 
     def _sha_cutoff_time(self):
         timestamp = super(InstrumentedDirState, self)._sha_cutoff_time()
-        return timestamp + self._time_offset
+        self._cutoff_time = timestamp + self._time_offset
 
     def _sha1_file(self, abspath, entry):
         self._log.append(('sha1', abspath))
@@ -1042,6 +1042,7 @@
         are in the past.
         """
         self._time_offset += secs
+        self._cutoff_time = None
 
 
 class _FakeStat(object):



More information about the bazaar-commits mailing list