Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements should cache its calls (like Provides does) #273

Open
d-maurer opened this issue Aug 15, 2023 · 0 comments
Open

Implements should cache its calls (like Provides does) #273

d-maurer opened this issue Aug 15, 2023 · 0 comments

Comments

@d-maurer
Copy link
Contributor

plone/Products.CMFPlone#3829 describes a case where the adapter factory lookup cache of zope.interface grows without limit causing severe memory problems.
I found the cause: plone.dexterity uses Implements (instead of Provides) in its implementation of the providedBy logic. While Provides supports efficient caching, Implements does not as demonstrated by

>>> from zope.interface import Interface
>>> from zope.interface.declarations import Implements, Provides
>>> class I(Interface): pass
... 
>>> I1 = Implements(I); I2 = Implements(I)
>>> P1 = Provides(I); P2 = Provides(I)
>>> I1 == I2
False
>>> P1 == P2
True

Provides achieves this by caching its calls (in a WeakValueDict); Implements does not use such a cache.

While I think that plone.dexterity uses the wrong declaration type (Implements instead of Provides), I believe that Implements should cache its calls like Provides does to improve its caching support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant