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

Changes in the compiler and dictionary to make key sharing in classes more effective. #77

Closed
3 tasks
markshannon opened this issue Jul 29, 2021 · 1 comment

Comments

@markshannon
Copy link
Member

Effective key-sharing is important for memory use and performance of class instances. With #72 it will become even more important.
Unfortunately, there are a few patterns that interfere with key sharing, when we generate the set of keys dynamically.
Anecdotally, in real-world applications there are many classes where keys are not shared.

E.g.

class C:
    foo = None #default value
    def __init__(self):
         self.bar = 0
    def meth(self):
        self.foo = 1

Building key sets dynamically will result in the set {'bar'}. Any objects that lazily update foo will be unable to share keys. By statically analyzing the class in the compiler, we can see that the set {'bar','foo'} would be a better choice.
Instances that do not define foo will waste a small amount of memory, but the overall saving from improved sharing would more than compensate.

To do:

  • Gather data on the number and kinds of classes where key sharing does not currently work well.
  • Discuss of Python Dev exactly when dictionary ordering should apply. Possibly write a PEP
  • Implement generating key hints in compiler and using them in class creation.
@markshannon
Copy link
Member Author

Closing this in favor of the more dynamic approach of #30 and #72

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

No branches or pull requests

1 participant