C++: Improve Element::toString() performance#1366
Conversation
|
A bunch of tests are failing because their All the other tests look fine, but you'll need to update their Now that we've seen how much this change can affect test output, I think the change deserves to be mentioned in the change note. Please add a change note to describe how this change affects |
| /** A source code location referring to a type */ | ||
| class TypeMention extends Locatable, @type_mention { | ||
| override string toString() {result = "mention of " + getMentionedType()} | ||
| override string toString() {result = "type mention"} |
There was a problem hiding this comment.
Would it be sufficient to change this to result = "mention of " + getMentionedType().getName() to avoid the recursion? That would hopefully keep the more informative to-string.
There was a problem hiding this comment.
Yes, that would turn this into a PR that we can merge right away, without changes to tests or change note. I prefer result = "type mention" because then we avoid the time and space overhead of creating a new string for each type.
Another option would be result = getMentionedType().getName(), which would make the string informative again. It would be in line with variable accesses, whose toString is just the name of the variable. But as far as I know, nothing benefits from TypeMention.toString being informative -- except for one test that's easily fixed.
I would imagine they're fine but I failed to find the actual test failures in the logs. I suggest adding the |
jbj
left a comment
There was a problem hiding this comment.
The tests couldn't run because of conflicts in the change note, so you'll need to rebase. When the tests do run, I expect they'll fail because the expected files in the internal repo also need to be upgraded. You'll need to make a PR to the internal repo as well, making its submodule point to the head of this PR, which should be freshly rebased on ql:master (not on the current target of the submodule pointer). Here's the guide: https://docs.google.com/document/d/1zOra3INgr06hxeyH3AFHn9JmSm8yJNnpH3BVQOBL4-k/edit#heading=h.4dw5b4p0d86g
change-notes/1.21/analysis-cpp.md
Outdated
| - The taint tracking library now includes taint-specific edges for functions modeled in `semmle.code.cpp.models.interfaces.DataFlow`. | ||
| - The taint tracking library adds flow through library functions that are modeled in `semmle.code.cpp.models.interfaces.Taint`. Queries can add subclasses of `TaintFunction` to specify additional flow. | ||
| - There is a new `FoldExpr` class, representing C++17 fold expressions. | ||
| - The predicate `TypeMention.toString()` has been simplified to always return the string "`type mention`". This greatly improves performance when using `Expr.toString()` or its descendants. |
There was a problem hiding this comment.
Typo: Expr should be Element.
Also, let's not overstate the performance implications of this change. I like to avoid mentioning performance improvements and regressions in the change notes because even though it varies between releases, performance stays within the same ballpark over time while the quality of our results goes up.
What's important for customers to know is that if they have qltests that query every Element, then those tests will need their expected output updated.
4b6ec7b to
a952b5b
Compare
|
Must be committed together with https://git.semmle.com/Semmle/code/pull/32371 |
a952b5b to
8c09900
Compare
by removing recursion in TypeMention::toString().