-
Notifications
You must be signed in to change notification settings - Fork 19
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
ArraySolver: Tiny performance optimization #715
Conversation
for (auto secondIt = selects.begin(); *secondIt != first; ++secondIt) { | ||
ERef second = *secondIt; | ||
if (firstRoot == getRoot(second)) { continue; } // The selects are already the same, no lemma needed | ||
NodeRef arrayFirst = getNodeRef(getRoot(getArrayFromSelect(first))); | ||
NodeRef arraySecond = getNodeRef(getRoot(getArrayFromSelect(second))); | ||
if (arrayFirst == arraySecond or getIndexedRepresentative(arrayFirst, index) == getIndexedRepresentative(arraySecond, index)) { |
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.
getIndexedRepresentative(arrayFirst, index)
can also be computed right after arrayFirst
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.
Yes, but in this case, it is possible that in the original code, it would not be called at all :)
I mean, I don't want to spend time on this now. I think the whole method (at also its usage) needs investigation about how to improve it.
for (auto secondIt = selects.begin(); *secondIt != first; ++secondIt) { | ||
ERef second = *secondIt; | ||
if (firstRoot == getRoot(second)) { continue; } // The selects are already the same, no lemma needed | ||
NodeRef arrayFirst = getNodeRef(getRoot(getArrayFromSelect(first))); | ||
NodeRef arraySecond = getNodeRef(getRoot(getArrayFromSelect(second))); | ||
if (arrayFirst == arraySecond or getIndexedRepresentative(arrayFirst, index) == getIndexedRepresentative(arraySecond, index)) { | ||
std::unordered_set<PTRef, PTRefHash> undecidedEqualities; |
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.
What happens if this hash is made to reuse its storage? I.e. move it outside the loops and just call undecidedEqualities.clear()
here?
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 mean, it should work, but does it improve performance significantly?
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.
We cannot do that. The map is currently being moved into LemmaConditions
.
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.
Yes, but after moving and clearing it is again in a valid state. It may potentially reuse previously dynamically allocated storage, it depends on implementation.
2fcf805
to
2f72cc0
Compare
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.
LGTM (for now)
This is just a tiny optimization to not repeat the same work inside a loop when we can do it once before the loop.