Skip to content

C++: Speed up SuspiciousAddWithSizeof select #3352

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 1 commit into from
Apr 24, 2020

Conversation

jbj
Copy link
Contributor

@jbj jbj commented Apr 24, 2020

This select clause had become very slow after we started caching ElementBase::toString because the query used string concatenation to produce alert messages, and those string concatenations were done very early in the pipeline, producing lots of strings that would be discarded moments later.

By using $@ to interpolate elements into strings, the concatenation is done outside of QL.

Testing on a Chromium snapshot, this PR takes us from

#select#ff ................ 6m2s

to

#select#cpe#134#fff ....... 15.2s

This `select` clause had become very slow after we started caching
`ElementBase::toString` because the query used string concatenation to
produce alert messages, and those string concatenations were done very
early in the pipeline, producing lots of strings that would be discarded
moments later.

By using `$@` to interpolate elements into strings, the concatenation is
done outside of QL.

Testing on a Chromium snapshot, this commit takes us from

    #select#ff ................ 6m2s

to

    #select#cpe#134#fff ....... 15.2s
@jbj jbj added the C++ label Apr 24, 2020
@jbj jbj added this to the 1.24 milestone Apr 24, 2020
@jbj jbj requested a review from a team as a code owner April 24, 2020 14:19
Copy link
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

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

LGTM (assuming the tests pass).

Would it be worthwhile to go through the LGTM suite and check if other queries suffer from the same issue? I suppose this can almost be done with a grep

@jbj
Copy link
Contributor Author

jbj commented Apr 24, 2020

Would it be worthwhile to go through the LGTM suite and check if other queries suffer from the same issue? I suppose this can almost be done with a grep

I'd prefer not to make queries uglier if they don't have a substantial performance problem. If we can solve https://github.com/github/codeql-c-analysis-team/issues/56 in the libraries and/or optimiser, that seems better than chasing down individual queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants