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
Add __slots__ to all classes #744
Comments
Hey, I wasn't aware that |
I don't know how much of a difference it will make, but the codebase is pretty class-heavy so I'm optimistic |
PyPy uses JIT, which generally uses a lot more memory, has slower startup times, but works faster. I'd expect most code running in PyPy to use more memory, unless you're getting to the hundred's of MB range. I'd be pretty surprised is slots helped that much either, definitely I don't think you should apply it to all classes but if there's some class that's getting instantiated thousands of times it would be a good thing to look at optimizing. Is this project really instantiating thousands and thousands of classes? |
There are some classes that are instantiated a lot (especially for the PolicyEngine), but a lot of the other classes use a lot of inheritance. Most things in this projects are class based, simply just because of django and drf. |
Well it will be interesting to see if this has any significant impact |
The PyPy comment was based on this page about |
How The only downside is you cannot get/set attributes that do not exist in this array and ALL objects in the inheritance chain MAY NOT use dicts for memory storage, i.e. they MUST also define |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I hate stale closing bot. It's the worst bot. I mean don't get my wrong, I don't think adding |
I got bored of working on this, so it's fine for stale bot to close it if it wants. |
@traverseda My bad, I didn't fully think through configuring stale bot when I initially added it. I re-opened this issue with a |
Is your feature request related to a problem? Please describe.
High memory usage
Describe the solution you'd like
Add the special
__slots__
class variable to all or most classes.Describe alternatives you've considered
Using an alternative Python interpreter such as PyPy can also reduce memory usage as PyPy does some optimisations like this already. However, PyPy lacks some features of CPython (especially the C API).
Additional context
If you're not familiar with
__slots__
, see here.I'm working on a PR already, but I thought I'd create an issue first to track progress.
The text was updated successfully, but these errors were encountered: