diff options
author | Jens W. Klein <jk@kleinundpartner.at> | 2020-01-28 14:19:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-28 14:19:14 +0100 |
commit | 489328a5afc1430a064db2dba7a7a408591789f9 (patch) | |
tree | 1b7aca7e01142ef712049e1c714ccb513cd094cb | |
parent | 49126928256538029ed8ae51c38cc945d726fd7d (diff) | |
parent | 7f070c295995903005a080540d217c1acf64160f (diff) | |
download | zope-interface-489328a5afc1430a064db2dba7a7a408591789f9.tar.gz |
Merge pull request #161 from zopefoundation/hash_performance_2
Remove unneeded overwrite and call to anyway inherited __hash__ method
-rw-r--r-- | CHANGES.rst | 7 | ||||
-rw-r--r-- | src/zope/interface/declarations.py | 7 |
2 files changed, 9 insertions, 5 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index cfb52d4..ad7140b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -54,6 +54,13 @@ fields in your subclass before attempting to hash or sort it. See `issue 157 <https://github.com/zopefoundation/zope.interface/issues/157>`_. +- Remove unneeded overwrite and call to anyway inherited `__hash__` method + from `.declarations.Implements` class. Watching a reindex index process in + ZCatalog with on a Py-Spy after 10k samples the time for `.adapter._lookup` + was reduced from 27.5s to 18.8s (~1.5x faster). Overall reindex index time + shrunk from 369s to 293s (1.26x faster). See + `PR 161 <https://github.com/zopefoundation/zope.interface/pull/161>`_. + 4.7.1 (2019-11-11) ================== diff --git a/src/zope/interface/declarations.py b/src/zope/interface/declarations.py index 83f424c..97ccd55 100644 --- a/src/zope/interface/declarations.py +++ b/src/zope/interface/declarations.py @@ -223,15 +223,12 @@ class Implements(Declaration): # This spelling works under Python3, which doesn't have cmp(). return (n1 > n2) - (n1 < n2) - def __hash__(self): - return Declaration.__hash__(self) - - # We want equality to be based on identity. However, we can't actually + # We want equality and hashing to be based on identity. However, we can't actually # implement __eq__/__ne__ to do this because sometimes we get wrapped in a proxy. # We need to let the proxy types implement these methods so they can handle unwrapping # and then rely on: (1) the interpreter automatically changing `implements == proxy` into # `proxy == implements` (which will call proxy.__eq__ to do the unwrapping) and then - # (2) the default equality semantics being identity based. + # (2) the default equality and hashing semantics being identity based. def __lt__(self, other): c = self.__cmp(other) |