-
Notifications
You must be signed in to change notification settings - Fork 518
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
Exploit repeated named expressions in identify_variables
#3190
Conversation
…tify_variables_in_expressions
Test failures are in a GDP baseline file comparison, likely due to changes in variable order generated by |
We discussed a few implementation changes during the dev call today so I'm going to mark this as a draft for now |
… expression cache
…nt named expression handling
I had to update some tests to use I think the reason for the difference is that |
With this patch, the motivating example from #3186 looks pretty good: Identifier ncalls cumtime percall %
--------------------------------------------------------------------------------
root 1 2.348 2.348 100.0
---------------------------------------------------------------------------
full model post-solve 1 0.460 0.460 19.6
solve-scc 1 1.888 1.888 80.4
------------------------------------------------------
identify-variables 546 0.188 0.000 10.0
other n/a 1.700 n/a 90.0
======================================================
other n/a 0.000 n/a 0.0
===========================================================================
================================================================================ |
get_vars_from_components
identify_variables
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3190 +/- ##
=======================================
Coverage 88.40% 88.40%
=======================================
Files 846 846
Lines 95156 95207 +51
=======================================
+ Hits 84118 84169 +51
Misses 11038 11038
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
I think there is a significantly more compact implementation of this, but there is certainly nothing wrong with this. I propose merging this, and defer improvements into a later PR.
Fixes #3187
Summary/Motivation:
identify_variables
can be responsible for a non-trivial portion of runtime for models with many occurrences of large named expressions. This PR adds a new variable visitor that supportsdescend_into_named_expressions=False
and updatesget_vars_from_components
to use this new visitor to avoid re-checking the same named expression multiple times.The potential performance hit is most pronounced when identifying variables for many expressions in a model, so I've only used this visitor inget_vars_from_components
. This functionality could also be useful inidentify_variables
, but I wanted to get some feedback before implementing this.Edit: This PR now updates
identify_variables
.Changes proposed in this PR:
_StreamVariableVisitor
... I'm open to suggestions)identify_variables
to use this visitor and add an optionalnamed_expression_cache
argumentnamed_expression_cache
inget_vars_from_components
Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: