Skip to content

astutils.cpp: optimized followAllReferences() a bit #5442

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

Merged
merged 3 commits into from
Dec 13, 2023

Conversation

firewave
Copy link
Collaborator

@firewave firewave commented Sep 12, 2023

Scanning common/file.c of the xrdp project with --force --std=c11 --std=c++11 --inline-suppr --enable=warning:

Clang 16 4,208,373,435 -> 4,143,907,657
Clang 16 (Boost) 3,837,285,621 -> 3,609,164,192
GCC 13 4,336,042,153 -> 4,331,137,034
GCC 13 (Boost) 3,896,319,383 -> 3,795,013,995

@firewave firewave changed the title optimized and refactored followAlReferences() a bit optimized and refactored followAllReferences() a bit Sep 12, 2023
lib/astutils.cpp Outdated
if (argvar->isArgument() && (argvar->isReference() || argvar->isRValueReference())) {
const int n = getArgumentPos(argvar, f);
if (n < 0) {
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

This changes the behavior. Instead of exiting function this will only exit the for loop.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is intentional. It exits the loop, result is empty and then it goes to the code at the end of the function...but that doesn't happen because I overlooked the outer loop over returns...well spotted.

@firewave
Copy link
Collaborator Author

Best use split view and "hide whitespaces" option to properly review this since the indentation changed.

lib/astutils.cpp Outdated
er.emplace_back(tok->previous(), "Called function passing '" + argTok->expressionString() + "'.");
auto refs =
followAllReferences(argTok, temporary, inconclusive, std::move(er), depth - returns.size());
if (!inconclusive && refs.size() > 1) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This behavior for this and the following lines has also changed. Again I missed the outer loop so result might have been set in an earlier iteration.

But if we hit this block more than once we bailed out when the prerequisites were not met even though we might already have entries in result. If that should/can never happen or is unintentional we also need to exit after we added something to result.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Or we should have continued instead of returned.

@firewave
Copy link
Collaborator Author

As this did not cause any tests to fail I wonder if we should have a test on a fixed source where we generate the ValueFlow debug output and compare it. Same for the AST/generated code. That would be quite massive but we would see the actual impact.

@firewave
Copy link
Collaborator Author

firewave commented Nov 8, 2023

I removed the last commit which had the problematic changes. The other changes already yield similar improvements and are safe. Will provide updated performance numbers soon.

@firewave firewave changed the title optimized and refactored followAllReferences() a bit optimized followAllReferences() a bit Nov 8, 2023
@firewave firewave marked this pull request as ready for review November 16, 2023 09:29
@firewave firewave marked this pull request as draft November 16, 2023 13:40
@firewave
Copy link
Collaborator Author

Using push_back() or emplace_back() does not make any difference. Neither does using the move iterators. Will try a heavier example to verify this.

@firewave firewave changed the title optimized followAllReferences() a bit astutils.cpp: optimized followAllReferences() a bit Nov 26, 2023
@firewave firewave marked this pull request as ready for review December 2, 2023 12:14
@firewave
Copy link
Collaborator Author

firewave commented Dec 2, 2023

Ready for review - again.

Copy link
Owner

@danmar danmar left a comment

Choose a reason for hiding this comment

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

lgtm

@firewave firewave added merge-after-next-release Wait with merging this PR until after the next Release and removed merge-after-next-release Wait with merging this PR until after the next Release labels Dec 13, 2023
@firewave firewave merged commit d7835f1 into danmar:main Dec 13, 2023
@firewave firewave deleted the follow branch December 13, 2023 20:08
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.

4 participants