Skip to content
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

Merged
merged 1 commit into from
May 16, 2024
Merged

Conversation

blishko
Copy link
Member

@blishko blishko commented May 16, 2024

This is just a tiny optimization to not repeat the same work inside a loop when we can do it once before the loop.

@blishko blishko requested a review from Tomaqa May 16, 2024 11:57
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)) {
Copy link
Member

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

Copy link
Member Author

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;
Copy link
Member

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?

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

@blishko blishko force-pushed the array-solver-tiny-opt branch from 2fcf805 to 2f72cc0 Compare May 16, 2024 13:30
Copy link
Member

@Tomaqa Tomaqa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (for now)

@blishko blishko merged commit 2f72cc0 into master May 16, 2024
8 checks passed
@blishko blishko temporarily deployed to github-pages May 16, 2024 14:12 — with GitHub Pages Inactive
@blishko blishko deleted the array-solver-tiny-opt branch May 16, 2024 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants