-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
variables map grows in size #10
Comments
In general, a variable can exist in more than one constraint, and tracking when a variable no longer appears in any constraints would be expensive. If you want to fully clear a solver, you can call |
Yes, but uncontrollable growing is sometimes more troblesome than expenses due to variables cleanup. That is exactly my case, long run solver with frequently changing constraints set eventually leaks all the RAM. Can you please provide some hints how to implement variables cleanup functionality? |
In Enaml, such unbounded growth could occur by continuously adding and removing new widgets from a layout, but Enaml deals with this case by resetting the solver when it gets new layout items and re-adding all relevant constraints. https://github.com/nucleic/enaml/blob/master/enaml/layout/layout_manager.py#L295 I would suggest you follow a similar model and pick a reasonable time to reset the solver and then re-add all of your still-valid constraints. Checking whether a variable is still contained in the solver requires a linear scan over all rows in the solver. For a constraint with M variables, that would be an O(M x N) operation. Scanning for all empty variables would be O(N^2), at which point it's just cheaper to reset. |
Alternatively, you can reuse your old variables in your new constraints. i.e. manage your own free variable pool. |
Thanks! Periodically reset and re-add constraints should work for me. |
thread keyword to allow people like me to find it more easily: |
In dynamic environment, when constraints added and removed frequently, solver's variables map grows in size. It is because variable never removed from map even if every constraint it is used in are removed. Here is the code:
I expected no variables, but got:
The text was updated successfully, but these errors were encountered: