-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C++: Improve PrintAST performance. #4680
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
Conversation
Co-authored-by: Jonas Jensen <jbj@github.com>
) | ||
or | ||
i = count(Specifier s) + 1 and res = "" | ||
} |
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.
Was this just ... very old code? (we've had concat
for a while now!)
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 didn't dig in the history - I suspect either it's very old or written by somebody who was fairly new to QL at the time.
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.
Hrm. I assume that I wrote this, but it doesn't look like my style. In any case, nice improvement in both readability and performance.
How did you check performance? |
Manually on a single file from facebookincubator/fizz, the previous code took about 20sec, the new code takes about 100ms. |
@@ -1308,7 +1308,7 @@ class SpecifiedType extends DerivedType { | |||
* only depends on the specifiers, not on the source program). This is intended | |||
* for debugging queries only and is an expensive operation. | |||
*/ | |||
string getSpecifierString() { internalSpecString(this, result, 1) } | |||
string getSpecifierString() { result = concat(this.getASpecifier().getName(), " ") + " " } |
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.
How do you feel about removing the trailing space, and fixing up the three? places this predicate is used?
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 could do that, but in theory it is an API change.
It is rectified by the fact that the predicate is only for debugging, and that the whitespace behaviour is not documented, but still, at least in my opinion it's not a no-brainer.
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'm happy to accept this API change in a predicate that has "This is intended for debugging queries only" in its QLDoc.
This is a good reminder that we should be conscious about which APIs we make public. The QLDoc for getSpecifierString
should really start with "INTERNAL: do not use.", and ideally that predicate should not reside in Type.qll
at all.
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
Faster PrintAST with less and easier to understand code!