summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens W. Klein <jk@kleinundpartner.at>2020-02-16 18:09:08 +0100
committerJens W. Klein <jk@kleinundpartner.at>2020-02-16 18:13:44 +0100
commit70952aca35d7021dcce34149f38672aadd577f70 (patch)
tree376164084c63849a72f7fe3f289cd8c25a6acda7
parent7f6f60e824ac34e2bf9ec890e6c361f57bfc823b (diff)
downloadzope-interface-use-object-hash.tar.gz
Fixes #178: performace improvement by using objects hashuse-object-hash
-rw-r--r--CHANGES.rst10
-rw-r--r--src/zope/interface/interface.py9
2 files changed, 6 insertions, 13 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index d0ee2e8..923e3f0 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -18,13 +18,9 @@
value forces the Python implementation to be used, ignoring the C
extensions. See `PR 151 <https://github.com/zopefoundation/zope.interface/pull/151>`_.
-- Cache the result of ``__hash__`` method in ``InterfaceClass`` as a
- speed optimization. The method is called very often (i.e several
- hundred thousand times during Plone 5.2 startup). Because the hash value never
- changes it can be cached. This improves test performance from 0.614s
- down to 0.575s (1.07x faster). In a real world Plone case a reindex
- index came down from 402s to 320s (1.26x faster). See `PR 156
- <https://github.com/zopefoundation/zope.interface/pull/156>`_.
+- Improve performance by not using a custom ``InterfaceClass.__hash__``
+ function but use ``object.__hash__`` instead. For details see
+ `Issue 178 <https://github.com/zopefoundation/zope.interface/pull/156>`_.
- Change the C classes ``SpecificationBase`` and its subclass
``ClassProvidesBase`` to store implementation attributes in their structures
diff --git a/src/zope/interface/interface.py b/src/zope/interface/interface.py
index ade6f42..2e7d76f 100644
--- a/src/zope/interface/interface.py
+++ b/src/zope/interface/interface.py
@@ -596,12 +596,9 @@ class InterfaceClass(Element, InterfaceBase, Specification):
# This spelling works under Python3, which doesn't have cmp().
return (n1 > n2) - (n1 < n2)
- def __hash__(self):
- try:
- return self._v_cached_hash
- except AttributeError:
- self._v_cached_hash = hash((self.__name__, self.__module__))
- return self._v_cached_hash
+ # use the very fast object hash function, no need for custom impl
+ # see https://github.com/zopefoundation/zope.interface/issues/178
+ __hash__ = object.__hash__
def __eq__(self, other):
c = self.__cmp(other)