Skip to content

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

Merged
firewave merged 3 commits into
cppcheck-opensource:mainfrom
firewave:follow
Dec 13, 2023
Merged

astutils.cpp: optimized followAllReferences() a bit#5442
firewave merged 3 commits into
cppcheck-opensource:mainfrom
firewave:follow

Conversation

@firewave

@firewavefirewave commented Sep 12, 2023

Copy link
Copy Markdown
Collaborator

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

@firewavefirewave changed the title optimized and refactored followAlReferences() a bitoptimized and refactored followAllReferences() a bitSep 12, 2023
Comment threadlib/astutils.cpp Outdated
if (argvar->isArgument() && (argvar->isReference() || argvar->isRValueReference())) {
const int n = getArgumentPos(argvar, f);
if (n < 0) {
break;

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
CollaboratorAuthor

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
Copy Markdown
CollaboratorAuthor

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

Comment threadlib/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
Copy Markdown
CollaboratorAuthor

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
Copy Markdown
CollaboratorAuthor

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
Copy Markdown
CollaboratorAuthor

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
Copy Markdown
CollaboratorAuthor

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.

@firewavefirewave changed the title optimized and refactored followAllReferences() a bitoptimized followAllReferences() a bitNov 8, 2023
Comment threadlib/astutils.cpp
@firewave
firewave marked this pull request as ready for review November 16, 2023 09:29
Comment threadlib/astutils.cpp Outdated
Comment threadlib/astutils.cpp
@firewave
firewave marked this pull request as draft November 16, 2023 13:40
@firewave

Copy link
Copy Markdown
CollaboratorAuthor

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.

@firewavefirewave changed the title optimized followAllReferences() a bitastutils.cpp: optimized followAllReferences() a bitNov 26, 2023
@firewave
firewave marked this pull request as ready for review December 2, 2023 12:14
@firewave

Copy link
Copy Markdown
CollaboratorAuthor

Ready for review - again.

@danmardanmar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@firewavefirewave 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 cppcheck-opensource:mainDec 13, 2023
@firewave
firewave deleted the follow branch December 13, 2023 20:08
Sign up for freeto 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

@firewave@danmar@pfultz2@chrchr-github