Skip to content

Commit

Permalink
Merge 17f5082 into 02e11f2
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Jan 24, 2020
2 parents 02e11f2 + 17f5082 commit ce730d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Expand Up @@ -5,6 +5,13 @@
4.8.0 (unreleased)
==================

- Performance optimization of ``__hash__`` method on ``InterfaceClass``.
The method is called very often (i.e several 100.000 times on a 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 (todo)

- Support the ``PURE_PYTHON`` environment variable at runtime instead
of just at wheel build time. A value of 0 forces the C extensions to
be used (even on PyPy) failing if they aren't present. Any other
Expand Down
14 changes: 9 additions & 5 deletions src/zope/interface/interface.py
Expand Up @@ -538,11 +538,15 @@ def __cmp(self, other):
return (n1 > n2) - (n1 < n2)

def __hash__(self):
d = self.__dict__
if '__module__' not in d or '__name__' not in d: # pragma: no cover
warnings.warn('Hashing uninitialized InterfaceClass instance')
return 1
return hash((self.__name__, self.__module__))
try:
return self._cached_hash
except AttributeError:
try:
self._cached_hash = hash((self.__name__, self.__module__))
except AttributeError: # pragma: no cover
warnings.warn('Hashing uninitialized InterfaceClass instance')
return 1
return self._cached_hash

def __eq__(self, other):
c = self.__cmp(other)
Expand Down

0 comments on commit ce730d0

Please sign in to comment.