Skip to content

C++: Fix bad join in virtual dispatch - #22511

Merged
MathiasVP merged 1 commit into
github:mainfrom
MathiasVP:fix-join-in-virtual-dispatch
Sep 4, 2026
Merged

C++: Fix bad join in virtual dispatch#22511
MathiasVP merged 1 commit into
github:mainfrom
MathiasVP:fix-join-in-virtual-dispatch

Conversation

@MathiasVP

Copy link
Copy Markdown
Contributor

Before:

[2026-09-04 12:36:47] Evaluated non-recursive predicate DataFlowDispatch::TrackVirtualDispatch<noDisp>::TtInput::returnStep/2#64397117@7819e22o in 216ms (size: 1415417).
Evaluated relational algebra for predicate DataFlowDispatch::TrackVirtualDispatch<noDisp>::TtInput::returnStep/2#64397117@7819e22o with tuple counts:
        73694211  ~2%    {2} r1 = JOIN `_DataFlowDispatch::RelevantNode#d8b83544_DataFlowUtil::Node.getEnclosingCallable/0#dispred#74002437#shared` WITH `DataFlowDispatch::nonVirtualDispatch/1#f749a2ef_10#join_rhs` ON FIRST 1 OUTPUT Lhs.1, Rhs.1
         1425123  ~0%    {3}    | JOIN WITH `DataFlowPrivate::ReturnNode.getKind/0#dispred#c7586c0b` ON FIRST 1 OUTPUT Lhs.1, Rhs.1, Lhs.0
         1422517  ~0%    {2}    | JOIN WITH `DataFlowPrivate::getAnOutNode/2#fa64ae7d` ON FIRST 2 OUTPUT Rhs.2, Lhs.2
         1415417  ~2%    {2}    | JOIN WITH `DataFlowDispatch::TrackVirtualDispatch<d1>::TtInput::LocalSourceNode#9cbbba61` ON FIRST 1 OUTPUT Lhs.1, Lhs.0
                         return r1

After:

[2026-09-04 13:23:46] Evaluated non-recursive predicate DataFlowDispatch::hasKindAndEnclosingCallable/3#f9907305@df466fdu in 102ms (size: 614924).
Evaluated relational algebra for predicate DataFlowDispatch::hasKindAndEnclosingCallable/3#f9907305@df466fdu with tuple counts:
        614924  ~0%    {3} r1 = JOIN `DataFlowUtil::Node.getEnclosingCallable/0#dispred#74002437` WITH `DataFlowPrivate::ReturnNode.getKind/0#dispred#c7586c0b` ON FIRST 1 OUTPUT Lhs.1, Rhs.1, Lhs.0
                       return r1

[2026-09-04 13:23:47] Evaluated non-recursive predicate _DataFlowDispatch::RelevantNode#d8b83544_DataFlowDispatch::hasKindAndEnclosingCallable/3#f9907305#shared@13f314hb in 37ms (size: 470063).
Evaluated relational algebra for predicate _DataFlowDispatch::RelevantNode#d8b83544_DataFlowDispatch::hasKindAndEnclosingCallable/3#f9907305#shared@13f314hb with tuple counts:
        614924  ~0%    {3} r1 = SCAN `DataFlowDispatch::hasKindAndEnclosingCallable/3#f9907305` OUTPUT In.2, In.0, In.1
        470063  ~0%    {3}    | JOIN WITH DataFlowDispatch::RelevantNode#d8b83544 ON FIRST 1 OUTPUT Lhs.1, Lhs.2, Lhs.0
                       return r1

[2026-09-04 13:23:47] Evaluated non-recursive predicate DataFlowDispatch::TrackVirtualDispatch<noDisp>::TtInput::hasDispatchWithKind/3#0e8dc366@4d20b7ij in 235ms (size: 2025567).
Evaluated relational algebra for predicate DataFlowDispatch::TrackVirtualDispatch<noDisp>::TtInput::hasDispatchWithKind/3#0e8dc366@4d20b7ij with tuple counts:
        2025573  ~0%    {3} r1 = JOIN `_DataFlowDispatch::TrackVirtualDispatch<d1>::TtInput::LocalSourceNode#9cbbba61_DataFlowPrivate::getA__#shared` WITH `DataFlowDispatch::nonVirtualDispatch/1#f749a2ef` ON FIRST 1 OUTPUT Rhs.1, Lhs.2, Lhs.1
                        return r1

[2026-09-04 13:23:47] Evaluated non-recursive predicate DataFlowDispatch::TrackVirtualDispatch<noDisp>::TtInput::returnStep/2#64397117@4eb6ac89 in 77ms (size: 1415417).
Evaluated relational algebra for predicate DataFlowDispatch::TrackVirtualDispatch<noDisp>::TtInput::returnStep/2#64397117@4eb6ac89 with tuple counts:
        1415417  ~5%    {2} r1 = JOIN `_DataFlowDispatch::RelevantNode#d8b83544_DataFlowDispatch::hasKindAndEnclosingCallable/3#f9907305#shared` WITH `DataFlowDispatch::TrackVirtualDispatch<noDisp>::TtInput::hasDispatchWithKind/3#0e8dc366` ON FIRST 2 OUTPUT Lhs.2, Rhs.2
                        return r1

Copilot AI balanced review requested due to automatic review settings September 4, 2026 12:38
@MathiasVP
MathiasVP requested a review from a team as a code owner September 4, 2026 12:38
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Sep 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The refactoring is semantically equivalent and the supplied metrics confirm a substantially cheaper join plan.

Review tier: Balanced
Findings: None

What changed in this PR

Optimizes C++ virtual-dispatch return flow by splitting an inefficient join while preserving semantics.

Changes:

  • Precomputes return-node callable/kind relationships.
  • Separately computes dispatch targets by return kind.
File Description
cpp/​ql/​lib/​semmle/​code/​cpp/​ir/​dataflow/​internal/​DataFlowDispatch.qll Refactors returnStep joins for improved evaluation performance.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions github-actions Bot added the C++ label Sep 4, 2026

@jketema jketema left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM if DCA is happy.

@MathiasVP
MathiasVP merged commit 8b5ffea into github:main Sep 4, 2026
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C++ no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants