Rev 3883: Add an InventoryEntry cache to the xml deserializer. in http://bzr.arbash-meinel.com/branches/bzr/1.11/xml_cache
John Arbash Meinel
john at arbash-meinel.com
Mon Dec 8 18:28:15 GMT 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.11/xml_cache
------------------------------------------------------------
revno: 3883
revision-id: john at arbash-meinel.com-20081208182757-2rls8q1ri36ub6e9
parent: pqm at pqm.ubuntu.com-20081205181554-ofrdnafloc43bxkh
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: xml_cache
timestamp: Mon 2008-12-08 12:27:57 -0600
message:
Add an InventoryEntry cache to the xml deserializer.
-------------- next part --------------
=== modified file 'bzrlib/xml8.py'
--- a/bzrlib/xml8.py 2008-04-24 07:22:53 +0000
+++ b/bzrlib/xml8.py 2008-12-08 18:27:57 +0000
@@ -21,6 +21,7 @@
cache_utf8,
errors,
inventory,
+ lru_cache,
revision as _mod_revision,
)
from bzrlib.xml_serializer import SubElement, Element, Serializer
@@ -38,6 +39,8 @@
"<":"<",
">":">",
}
+# A cache of InventoryEntry objects
+_entry_cache = lru_cache.LRUCache(10*1024)
def _ensure_utf8_re():
@@ -361,10 +364,21 @@
get_cached = _get_utf8_or_ascii
+ file_id = elt.get('file_id')
+ revision = elt.get('revision')
+ # Check and see if we have already unpacked this exact entry
+ key = (file_id, revision)
+ cached_ie = _entry_cache.get(key, None)
+ if cached_ie is not None:
+ # We copy it, because some operatations may mutate it
+ return cached_ie.copy()
+
+ file_id = get_cached(file_id)
+ if revision is not None:
+ revision = get_cached(revision)
parent_id = elt.get('parent_id')
if parent_id is not None:
parent_id = get_cached(parent_id)
- file_id = get_cached(elt.get('file_id'))
if kind == 'directory':
ie = inventory.InventoryDirectory(file_id,
@@ -386,10 +400,8 @@
ie.symlink_target = elt.get('symlink_target')
else:
raise errors.UnsupportedInventoryKind(kind)
- revision = elt.get('revision')
- if revision is not None:
- revision = get_cached(revision)
ie.revision = revision
+ _entry_cache[key] = ie
return ie
More information about the bazaar-commits
mailing list