Rev 4734: Do a bit of memory tweaking. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-chk-memory

John Arbash Meinel john at arbash-meinel.com
Thu Oct 8 20:49:11 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1-chk-memory

------------------------------------------------------------
revno: 4734
revision-id: john at arbash-meinel.com-20091008194850-nigahumk4tj2uhy8
parent: pqm at pqm.ubuntu.com-20091008172636-tygnfi5hsnn9203g
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-chk-memory
timestamp: Thu 2009-10-08 14:48:50 -0500
message:
  Do a bit of memory tweaking.
  
  When loading all CHKInventory objects we hit 83MB of memory consumed.
  This drops to 77MB if we intern strings that are hit often.
  (The revision_id, the root id, search_key_name, and the parent_id_basename_to_file_id
  sha1.)
-------------- next part --------------
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2009-10-02 05:43:41 +0000
+++ b/bzrlib/inventory.py	2009-10-08 19:48:50 +0000
@@ -1494,6 +1494,9 @@
 
     def __init__(self, search_key_name):
         CommonInventory.__init__(self)
+        # Note: if just loading all CHKInventory objects, these two empty
+        #       dictionaries end up costing 7MB, because you have 25k
+        #       inventories * 2 dicts * 140bytes for an empty dictionary.
         self._fileid_to_entry_cache = {}
         self._path_to_fileid_cache = {}
         self._search_key_name = search_key_name
@@ -1918,11 +1921,13 @@
                 raise errors.BzrError('Duplicate key in inventory: %r\n%r'
                                       % (key, bytes))
             info[key] = value
-        revision_id = info['revision_id']
-        root_id = info['root_id']
-        search_key_name = info.get('search_key_name', 'plain')
-        parent_id_basename_to_file_id = info.get(
-            'parent_id_basename_to_file_id', None)
+        revision_id = intern(info['revision_id'])
+        root_id = intern(info['root_id'])
+        search_key_name = intern(info.get('search_key_name', 'plain'))
+        # This is likely to be repeated often
+        parent_id_basename_to_file_id = intern(info.get(
+            'parent_id_basename_to_file_id', None))
+        # This is not
         id_to_entry = info['id_to_entry']
 
         result = CHKInventory(search_key_name)



More information about the bazaar-commits mailing list