C++: Improve PrintAST performance.#4680
Conversation
Co-authored-by: Jonas Jensen <jbj@github.com>
| ) | ||
| or | ||
| i = count(Specifier s) + 1 and res = "" | ||
| } |
There was a problem hiding this comment.
Was this just ... very old code? (we've had concat for a while now!)
There was a problem hiding this comment.
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.
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. |
| * 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.
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.
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.
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.
Faster PrintAST with less and easier to understand code!