Microoptimization: slots for _NumVarImpl#1021
Open
IgnaceBleukx wants to merge 1 commit into
Open
Conversation
Collaborator
|
oh nice, this is some of the benefits I was thinking we could only get with mypyc, so if we can get it pure python, great. In that SO post, it says parents also need slots, so strange this already works. But also, I wouldn't mind if 'name' becomes part of the slot of Expression, then there could be an even bigger win? or would that require using slots in all expressions? |
Collaborator
Author
|
Yes good point, we might as well have |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I recently learned about using
__slots__in python objectshttps://stackoverflow.com/questions/472000/usage-of-slots
The main advantage is that your objects take less memory, which may be very useful for models with loads of variables/constraints (e.g., files we read in from DIMACS?)
I've implemented it for _NumVarImpl, no real time gains, but memory footprint for a variable now goes from ±450B to ±80B which is nice : )
The real gains are probably when typing Operator and Comparison, or some of the globals (e.g., Multiplication).