-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C++: Fix performance issue on cpp/comma-before-misleading-indentation #10958
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
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.
A couple of questions. To me, this looks like a join order issue in the original code:
Tuple counts for _Call#39248e3c::Call::getAnArgument#0#dispred#ff_1#join_rhs__Expr#ef463c5d::Expr::getFullyConverted#__#antijoin_rhs/2@f9e794sd after 5m9s:
2476000 ~4% {2} r1 = JOIN _Expr#ef463c5d::Expr::getFullyConverted#0#dispred#ff_m#CommaBeforeMisleadingIndentation#36b1fbef::no__#shared WITH boundedFastTC:Expr#ef463c5d::Expr::getParentWithConversions#0#dispred#ff_10#higher_order_body:_Expr#ef463c5d::Expr::getFullyConverted#0#dispred#ff_m#CommaBeforeMisleadingIndentation#36b1fbef::no__#higher_order_body ON FIRST 1 OUTPUT Rhs.1 'arg1', Lhs.1 'arg0'
2482000 ~4% {2} r2 = _Expr#ef463c5d::Expr::getFullyConverted#0#dispred#ff_m#CommaBeforeMisleadingIndentation#36b1fbef::no__#shared UNION r1
354000 ~5% {2} r3 = JOIN r2 WITH Call#39248e3c::Call::getAnArgument#0#dispred#ff_1#join_rhs ON FIRST 1 OUTPUT Lhs.1 'arg0', Lhs.0 'arg1'
9424361000 ~1% {3} r4 = JOIN r2 WITH boundedFastTC:Expr#ef463c5d::Expr::getParentWithConversions#0#dispred#ff:__Expr#ef463c5d::Expr::getFullyConverted#0#dispred#ff_m#CommaBeforeMisleadingIndentation#36b1fbef::n__#higher_order_body ON FIRST 1 OUTPUT Rhs.1, Lhs.1 'arg0', Lhs.0 'arg1'
0 ~0% {2} r5 = JOIN r4 WITH Call#39248e3c::Call::getAnArgument#0#dispred#ff_1#join_rhs ON FIRST 1 OUTPUT Lhs.1 'arg0', Lhs.2 'arg1'
354000 ~5% {2} r6 = r3 UNION r5
return r6
I was able to hand-hold the optimizer to get rid of this join order here. It's still not as fast as your version, though.
cpp/ql/src/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation.ql
Outdated
Show resolved
Hide resolved
or | ||
not e.getLocation().getStartColumn() = min(getCandidateColumn(e)) and | ||
result = normalizeExpr(childWithConversions(e)) and | ||
result.getLocation().getStartColumn() = min(getCandidateColumn(e)) |
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.
Is this final conjunct necessary to prevent the normalizeExpr
call on line 47 from having multiple results? If so, could we get rid of this final conjunct by wrapping line 47 in a min
that orders by the start location? (Or does this run into non-monotonicity issues?
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 believe line 48 is necessary to ensure we get a global minimum Expr
, not just the minimum under one particular subtree (child of e
). It doesn't appear to affect any of the tests if I remove it, but I think it would be wrong to do so.
Wrapping line 47 in min
does indeed hit non-monotonicity issues (which seem to plague this particular predicate).
cpp/ql/src/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation.ql
Show resolved
Hide resolved
I wonder if the restrictions you use here ( |
I haven't been able to find an effective way to combine them. :( |
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!
C++: Fix rare performance issue on
cpp/comma-before-misleading-indentation
. The issue was_Call#39248e3c::Call::getAnArgument#0#dispred#ff__Expr#ef463c5d::Expr::getFullyConverted#0#dispred#f__#higher_order_body
exploding (found onnba-emu_NanoBoyAdvance
), which I interpret to mean thatnormalizeExpr
was just getting too big on deepExpr
trees (probably with lots of co-located hiddenExpr
s).The new solution calculates the lowest relevant column number first (
min(getCandidateColumn(e))
), which should be less affected by co-locatedExpr
s. Then in the main calculation that follows a lot ofExpr
s can be culled early using this relation.Its unfortunately more code than before but I've tried to explain in the comments.
I'll run DCA on this, but here are some local stats:
@MathiasVP