Skip to content

Optimize Group::select() with short-circuit checks before positionEdgeVariables()#622

Merged
highperformancecoder merged 3 commits intobugfix-610-unable-to-pull-wirefrom
copilot/sub-pr-621
Mar 11, 2026
Merged

Optimize Group::select() with short-circuit checks before positionEdgeVariables()#622
highperformancecoder merged 3 commits intobugfix-610-unable-to-pull-wirefrom
copilot/sub-pr-621

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

Canvas::itemAt() hit-tests every group via clickType()select(), which unconditionally called positionEdgeVariables() — an expensive operation invoking margins() (Pango bounding-box updates) and moveTo() on every edge variable, even for groups nowhere near the click point.

Changes

  • Empty-list short-circuit: return nullptr immediately when both inVariables and outVariables are empty — zero overhead for groups with no edge variables.
  • Bounds short-circuit: skip positionEdgeVariables() when (x,y) is outside a conservative AABB centered on the group. Uses maxExtent = w + h as the half-extent, which is a tight upper bound for any rotation angle (for half-dims w, h, the rotated AABB half-dim satisfies w|cosθ| + h|sinθ| ≤ w + h).
// Short-circuit: no edge variables to hit-test.
if (inVariables.empty() && outVariables.empty())
  return nullptr;

// Short-circuit: skip expensive positionEdgeVariables() when clearly outside bounds.
const float z = zoomFactor();
const float w = 0.5f * iWidth() * z;
const float h = 0.5f * iHeight() * z + topMargin * z;
const float maxExtent = w + h;
if (abs(x - this->x()) > maxExtent || abs(y - this->y()) > maxExtent)
  return nullptr;

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


This change is Reviewable

…eVariables()

Co-authored-by: highperformancecoder <3075825+highperformancecoder@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP Address feedback from Antigravity PR review comments Optimize Group::select() with short-circuit checks before positionEdgeVariables() Mar 11, 2026
@highperformancecoder highperformancecoder marked this pull request as ready for review March 11, 2026 04:04
Copilot AI review requested due to automatic review settings March 11, 2026 04:04
@highperformancecoder highperformancecoder merged commit a81c4a6 into bugfix-610-unable-to-pull-wire Mar 11, 2026
5 checks passed
@highperformancecoder highperformancecoder deleted the copilot/sub-pr-621 branch March 11, 2026 04:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes canvas hit-testing by reducing unnecessary work in Group::select() during Canvas::itemAt() calls, avoiding expensive edge-variable positioning/layout in common “miss” cases.

Changes:

  • Add an early return when both inVariables and outVariables are empty.
  • Add a bounding-box-based early return to skip positionEdgeVariables() when the click point is clearly outside a conservative extent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +1242 to +1251
// Short-circuit: avoid the expensive positionEdgeVariables() call when
// (x,y) is clearly outside the expanded group bounding box. Using
// w+h as the conservative AABB half-extent covers all rotation angles.
const float z = zoomFactor();
const float w = 0.5f * iWidth() * z;
const float h = 0.5f * iHeight() * z + topMargin * z;
const float maxExtent = w + h;
if (abs(x - this->x()) > maxExtent || abs(y - this->y()) > maxExtent)
return nullptr;

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

The new AABB short-circuit uses only the group icon dims (iWidth/iHeight + topMargin) to decide whether to skip positionEdgeVariables(). However edge variables can be laid out well outside those bounds (eg yOff grows with the number/height of in/out variables in layoutEdgeVariables), so this can return nullptr even when (x,y) is actually over a drawn edge variable/port, breaking hit-testing/wire dragging for groups with many edge vars (and potentially large label extents/margins). Consider widening the bound using a conservative upper bound that includes possible edge-variable extents (eg based on counts and cached bb heights/widths), caching margins/edge-extents from the last layout, or removing this short-circuit if correctness can’t be guaranteed.

Suggested change
// Short-circuit: avoid the expensive positionEdgeVariables() call when
// (x,y) is clearly outside the expanded group bounding box. Using
// w+h as the conservative AABB half-extent covers all rotation angles.
const float z = zoomFactor();
const float w = 0.5f * iWidth() * z;
const float h = 0.5f * iHeight() * z + topMargin * z;
const float maxExtent = w + h;
if (abs(x - this->x()) > maxExtent || abs(y - this->y()) > maxExtent)
return nullptr;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants