[Checkins] SVN: mongopersist/trunk/ - Performance: Switched to ``repoze.lru`` (from ``lru``), which is much
Stephen Richter
cvs-admin at zope.org
Fri Apr 6 02:41:48 UTC 2012
Log message for revision 124984:
- Performance: Switched to ``repoze.lru`` (from ``lru``), which is much
faster.
- Performance: To avoid excessive hash computations, we now use the hash of
the ``DBRef`` references as cache keys.
- Bug: ``ObjectId`` ids are not guarantted to be unique accross
collections. Thus they are a bad key for global caches. So we use full
``DBRef`` references instead.
Changed:
U mongopersist/trunk/CHANGES.txt
U mongopersist/trunk/setup.py
U mongopersist/trunk/src/mongopersist/mapping.py
U mongopersist/trunk/src/mongopersist/serialize.py
U mongopersist/trunk/versions.cfg
-=-
Modified: mongopersist/trunk/CHANGES.txt
===================================================================
--- mongopersist/trunk/CHANGES.txt 2012-04-06 01:15:07 UTC (rev 124983)
+++ mongopersist/trunk/CHANGES.txt 2012-04-06 02:41:43 UTC (rev 124984)
@@ -5,8 +5,16 @@
0.7.1 (2012-04-??)
------------------
-- ...
+- Performance: Switched to ``repoze.lru`` (from ``lru``), which is much
+ faster.
+- Performance: To avoid excessive hash computations, we now use the hash of
+ the ``DBRef`` references as cache keys.
+
+- Bug: ``ObjectId`` ids are not guarantted to be unique accross
+ collections. Thus they are a bad key for global caches. So we use full
+ ``DBRef`` references instead.
+
0.7.0 (2012-04-02)
------------------
Modified: mongopersist/trunk/setup.py
===================================================================
--- mongopersist/trunk/setup.py 2012-04-06 01:15:07 UTC (rev 124983)
+++ mongopersist/trunk/setup.py 2012-04-06 02:41:43 UTC (rev 124984)
@@ -40,7 +40,7 @@
),
install_requires = [
'transaction >=1.1.0',
- 'lru',
+ 'repoze.lru',
'pymongo',
'setuptools',
'zope.dottedname',
Modified: mongopersist/trunk/src/mongopersist/mapping.py
===================================================================
--- mongopersist/trunk/src/mongopersist/mapping.py 2012-04-06 01:15:07 UTC (rev 124983)
+++ mongopersist/trunk/src/mongopersist/mapping.py 2012-04-06 02:41:43 UTC (rev 124984)
@@ -12,6 +12,7 @@
#
##############################################################################
"""Mongo Mapping Implementations"""
+from __future__ import absolute_import
import UserDict
import pymongo
Modified: mongopersist/trunk/src/mongopersist/serialize.py
===================================================================
--- mongopersist/trunk/src/mongopersist/serialize.py 2012-04-06 01:15:07 UTC (rev 124983)
+++ mongopersist/trunk/src/mongopersist/serialize.py 2012-04-06 02:41:43 UTC (rev 124984)
@@ -15,7 +15,7 @@
from __future__ import absolute_import
import copy_reg
-import lru
+import repoze.lru
import persistent.interfaces
import persistent.dict
import persistent.list
@@ -32,7 +32,7 @@
ALWAYS_READ_FULL_DOC = True
SERIALIZERS = []
-OID_CLASS_LRU = lru.LRUCache(20000)
+OID_CLASS_LRU = repoze.lru.LRUCache(20000)
COLLECTIONS_WITH_TYPE = set()
AVAILABLE_NAME_MAPPINGS = set()
PATH_RESOLVE_CACHE = {}
@@ -278,7 +278,7 @@
obj._p_oid = pymongo.dbref.DBRef(coll_name, doc_id, db_name)
# Make sure that any other code accessing this object in this
# session, gets the same instance.
- self._jar._object_cache[doc_id] = obj
+ self._jar._object_cache[hash(obj._p_oid)] = obj
else:
doc['_id'] = obj._p_oid.id
# We only want to store a new version of the document, if it is
@@ -331,10 +331,9 @@
__traceback_info__ = dbref
# 1. Check the global oid-based lookup cache. Use the hash of the id,
# since otherwise the comparison is way too expensive.
- try:
- return OID_CLASS_LRU[hash(dbref.id)]
- except KeyError:
- pass
+ klass = OID_CLASS_LRU.get(hash(dbref))
+ if klass is not None:
+ return klass
# 2. Check the transient single map entry lookup cache.
try:
return self._single_map_cache[(dbref.database, dbref.collection)]
@@ -358,7 +357,7 @@
.find_one(dbref.id, fields=('_py_persistent_type',))
if '_py_persistent_type' in obj_doc:
klass = self.simple_resolve(obj_doc['_py_persistent_type'])
- OID_CLASS_LRU[hash(dbref.id)] = klass
+ OID_CLASS_LRU.put(hash(dbref), klass)
return klass
# 4. Try to resolve the path directly. We want to do this optimization
# after all others, because trying it a lot is very expensive.
@@ -423,7 +422,7 @@
break
else:
raise ImportError(dbref)
- OID_CLASS_LRU[dbref.id] = klass
+ OID_CLASS_LRU.put(hash(dbref), klass)
return klass
def get_non_persistent_object(self, state, obj):
@@ -536,7 +535,7 @@
def get_ghost(self, dbref, klass=None):
# If we can, we return the object from cache.
try:
- return self._jar._object_cache[dbref.id]
+ return self._jar._object_cache[hash(dbref)]
except KeyError:
pass
if klass is None:
@@ -551,5 +550,5 @@
obj._p_mongo_collection = dbref.collection
# Adding the object to the cache is very important, so that we get the
# same object reference throughout the transaction.
- self._jar._object_cache[dbref.id] = obj
+ self._jar._object_cache[hash(dbref)] = obj
return obj
Modified: mongopersist/trunk/versions.cfg
===================================================================
--- mongopersist/trunk/versions.cfg 2012-04-06 01:15:07 UTC (rev 124983)
+++ mongopersist/trunk/versions.cfg 2012-04-06 02:41:43 UTC (rev 124984)
@@ -60,12 +60,6 @@
# Added by Buildout Versions at 2011-09-24 09:27:33.494988
zope.testing = 3.10.2
-# Added by Buildout Versions at 2011-09-24 14:51:21.175710
-
-# Required by:
-# mongopersist==0.1dev
-lru = 0.1
-
# Added by Buildout Versions at 2011-09-24 22:10:37.470253
zope.container = 3.12.0
zope.contenttype = 3.5.3
@@ -198,3 +192,9 @@
# Added by Buildout Versions at 2011-11-02 11:39:09.460549
z3c.coverage = 1.2.0
+
+# Added by Buildout Versions at 2012-04-05 11:47:16.836718
+
+# Required by:
+# mongopersist==0.7.1.dev0
+repoze.lru = 0.3
More information about the checkins
mailing list