-
Couldn't load subscription status.
- Fork 1.2k
Slots #625
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
Slots #625
Conversation
|
This improved memory utilization in our use case by a factor of x20. |
tests/document/instance.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strongly backward incompatible.
|
Thank you for such a contribution. It looks like braking a lot of stuff that is used widely. I think that here is the place for an alternative BaseDocument class. Say StrictDocument. That would allow consume less memory in trade of lack of functionality. |
|
There is already DynamicDocument which is non strict and also even stores Is the functionality of storing extra unsaved data really used widely? It's possible to relax this a little and simply ignore any extra args. what do you think? |
|
@lig - thank you for your comments! I changed the implementation such that it now allows for previously undeclared fields (thus breaking nothing!), but still greatly optimizing for declared fields. A hash table is only created if absolutely necessary. I also added a class member 'STRICT' to allow using the 'strict' implementation (IMO it's generally safer...) |
|
What functionality would be lost if this is used? |
|
@ispmarin - absolutely no functionality would be lost (as far as I understand). |
|
There is no 100% coverage in this project. Ability to save data that is not declared in class attributes will be Also I think using I dont like Maybe we should put |
|
@lig - thanks for following up.
|
|
Sagiv, I completely understand you point. It looks like it is good enough |
|
OK, so I looked a bit deeper into it. It's (as far as I can see) impossible to achieve this by metaclasses, since you need to be able to both |
|
Sagiv, any function could be a member of the class. Say classmethod. |
changed the _data field to static key-value mapping instead of hash table This implements MongoEngine#624
|
@lig, I'm fully convinced. Please see updated commit. |
This implements issue #624:
This drastically reduces the memory footprint when loading many instances of the same class.