Skip to content

Conversation

criemen
Copy link
Collaborator

@criemen criemen commented Nov 17, 2020

Faster PrintAST with less and easier to understand code!

Co-authored-by: Jonas Jensen <jbj@github.com>
@criemen criemen requested a review from dbartol November 17, 2020 16:48
@criemen criemen requested a review from a team as a code owner November 17, 2020 16:48
@github-actions github-actions bot added the C++ label Nov 17, 2020
@criemen criemen marked this pull request as draft November 17, 2020 17:43
@criemen criemen marked this pull request as ready for review November 17, 2020 17:51
)
or
i = count(Specifier s) + 1 and res = ""
}
Copy link
Contributor

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!)

Copy link
Collaborator Author

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.

Copy link

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.

@geoffw0
Copy link
Contributor

geoffw0 commented Nov 17, 2020

How did you check performance?

@criemen
Copy link
Collaborator Author

criemen commented Nov 17, 2020

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(), " ") + " " }
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

Copy link

@dbartol dbartol left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants