Merge eats memory

Andrew Bennetts andrew at canonical.com
Fri Jun 3 06:40:53 BST 2005


On Fri, Jun 03, 2005 at 01:12:29PM +1000, Michael Ellerman wrote:
[...]
> 
> This is from merging a 30K patch between two kernel trees (no .git), it took 
> about 8m44s.
> 
> The last entry in the refs log (attached) comes out as:
> 
> Refcount	Class
> -------------------------------------------------------
> 55319		bzrlib.merge.SourceFile
> 55317		bzrlib.inventory.InventoryEntry
> 134		bzrlib.commands.Command
[...]

Here's a possible band-aid: it won't reduce the refcounts at all, but it
should hopefully reduce the memory footprint a little, and reduce the number
of object allocations Python does, by using __slots__.

I'd be curious to know if you get a noticeable speed boost or drop in memory
consumption from this.  I suspect the benefit will be minimal, but it didn't
take long to code :)

-Andrew.

-------------- next part --------------
*** modified file 'bzrlib/inventory.py'
--- bzrlib/inventory.py 
+++ bzrlib/inventory.py 
@@ -98,8 +98,8 @@
     # TODO: split InventoryEntry into subclasses for files,
     # directories, etc etc.
 
-    text_sha1 = None
-    text_size = None
+    __slots__ = ['file_id', 'name', 'kind', 'directory_id', 'text_sha1',
+                 'text_size', 'text_id', 'children', 'parent_id']
     
     def __init__(self, file_id, name, kind, parent_id, text_id=None):
         """Create an InventoryEntry
@@ -119,6 +119,8 @@
         if '/' in name or '\\' in name:
             raise BzrCheckError('InventoryEntry name %r is invalid' % name)
         
+        self.text_sha1 = None
+        self.text_size = None
         self.file_id = file_id
         self.name = name
         self.kind = kind

*** modified file 'bzrlib/merge.py'
--- bzrlib/merge.py 
+++ bzrlib/merge.py 
@@ -59,6 +59,8 @@
         self.add_suffix(target, ".moved")
             
 class SourceFile(object):
+    __slots__ = ['path', 'id', 'present', 'isdir', 'interesting']
+
     def __init__(self, path, id, present=None, isdir=None):
         self.path = path
         self.id = id

*** modified file 'bzrlib/xml.py'
--- bzrlib/xml.py 
+++ bzrlib/xml.py 
@@ -32,7 +32,9 @@
 import os, time
 from trace import mutter
 
-class XMLMixin:
+class XMLMixin(object):
+    __slots__ = []
+
     def to_element(self):
         raise Exception("XMLMixin.to_element must be overridden in concrete classes")
     



More information about the bazaar mailing list