Rev 5364: Add a __sizeof__ member for DeltaIndex. in http://bazaar.launchpad.net/~jameinel/bzr/2.3-sizeof

John Arbash Meinel john at arbash-meinel.com
Wed Jul 28 22:57:58 BST 2010


At http://bazaar.launchpad.net/~jameinel/bzr/2.3-sizeof

------------------------------------------------------------
revno: 5364
revision-id: john at arbash-meinel.com-20100728215742-esfp3yi4awd39070
parent: john at arbash-meinel.com-20100728215251-ylmowc0jmddlbmuc
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.3-sizeof
timestamp: Wed 2010-07-28 16:57:42 -0500
message:
  Add a __sizeof__ member for DeltaIndex.
  
  Even an 'empty' DeltaIndex consumes 780kB, because of the sources list.
  We really should consider changing how that is allocated. Though if we
  only ever have 1 of these objects it probably isn't terrible.
  We should also start paying attention to the size of the
  _delta_index attribute. We'll see if it matters in the future.
-------------- next part --------------
=== modified file 'bzrlib/_groupcompress_pyx.pyx'
--- a/bzrlib/_groupcompress_pyx.pyx	2010-02-17 17:11:16 +0000
+++ b/bzrlib/_groupcompress_pyx.pyx	2010-07-28 21:57:42 +0000
@@ -53,6 +53,7 @@
              unsigned long *delta_size, unsigned long max_delta_size) nogil
     unsigned long get_delta_hdr_size(unsigned char **datap,
                                      unsigned char *top) nogil
+    unsigned long sizeof_delta_index(delta_index *index)
     Py_ssize_t DELTA_SIZE_MIN
 
 
@@ -105,6 +106,13 @@
         if source is not None:
             self.add_source(source, 0)
 
+    def __sizeof__(self):
+        # We want to track the _source_infos allocations, but the referenced
+        # void* are actually tracked in _sources itself.
+        return (sizeof(DeltaIndex)
+            + (sizeof(source_info) * self._max_num_sources)
+            + sizeof_delta_index(self._index))
+
     def __repr__(self):
         return '%s(%d, %d)' % (self.__class__.__name__,
             len(self._sources), self._source_offset)



More information about the bazaar-commits mailing list