Skip to content

Reduce the work of node drag and node hover - #571

Closed
Doome161 wants to merge 2 commits into
paceholder:masterfrom
Doome161:perf/node-drag-and-hover
Closed

Doome161 wants to merge 2 commits into
paceholder:masterfrom
Doome161:perf/node-drag-and-hover

Conversation

@Doome161

@Doome161 Doome161 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation/refactoring

Description

Two performance fixes in NodeGraphicsObject. One commit each.

Move the connections of a dragged node once per mouse move.
The scene moves the node when the model reports the new position. itemChange() then
moves the connections of the node. mouseMoveEvent() moved them a second time, so each
connection was moved and repainted twice per mouse move. The second call came with the
group support. The group branch (groupGraphicsObject().moveConnections()) is unchanged.

Test only raised items for overlap when a node is hovered.
hoverEnterEvent() lowers the raised items that overlap the node. It called
collidingItems(), which tests the shape of every overlapping item. A node always overlaps
its own connections, so each hover built the stroke of every connection of the node.
Only items with a z value above 0 can change. The loop now checks the z value first and runs
the shape test only for those items. The set of lowered items is the same as before.
The loop reads scene()->items(). This sorts the items once per hover enter, not per mouse
move.

Testing

  • Qt version tested: Qt 6.8.3, MSVC 19.44, Windows 11 (shared library build)
  • Existing tests still pass (test_nodes: 98 test cases, 972 assertions)
  • Added tests for new functionality (if applicable)

New tests:

  • A node drag moves the connections of the node once per mouse move counts the connection
    lookups for one mouse move, with grouping on and off. It fails without the fix (2 instead
    of 1). It also checks that the connection follows the node before the release.
  • Hovering a node builds no connection strokes fails without the fix (1 stroke).
  • Hovering a node lowers the raised items that overlap it passes before and after the fix.
    It checks that an overlapping node and a raised connection are lowered, and that a distant
    node and a group keep their z value.

Not tested here: Qt 5, Linux and macOS. I rely on CI for these.

Timing, scene only, no view and no painting. One node with N connections, 1000 events.
Grouping off. The connection painter strokes the cubic once. Both builds come from clean
build folders: master at ea8718f, this PR at its head. The table shows two runs. Run 1 is
the median of 3 interleaved rounds. Run 2 is the median of 5 rounds, and the order of the two
builds alternates per round. Each round is the median of 7 samples.

Scenario N Run 1: master → PR (ms) Run 2: master → PR (ms) Change
Drag, 1000 mouse moves 1 14.2 → 8.8 13.4 → 8.2 -38 % / -39 %
Drag 10 108.2 → 57.4 100.5 → 53.2 -47 % / -47 %
Drag 50 547.9 → 276.9 570.8 → 254.3 -50 % / -55 %
Hover, 1000 enter/leave pairs 1 3.6 → 0.5 3.5 → 0.4 -86 % / -88 %
Hover 10 45.2 → 0.5 41.9 → 0.5 -99 % / -99 %
Hover 50 364.0 → 0.8 410.7 → 0.7 -99.8 % / -99.8 %

The machine is shared. Absolute times vary by about 5 to 10 % between runs. For drag with
N = 50, master varied from 527 to 644 ms between rounds, so that change is between -50 %
and -55 %.

Run 2 also counted the work of one run per scenario:

Scenario Lookups of the node's connections: master → PR Connection strokes: master → PR
Drag, N = 1, 10, 50 2001 → 1001 0 → 0
Hover, N = 1, 10, 50 0 → 0 1000, 10000, 50000 → 0

The extra lookup in each drag run comes from the final position check of the benchmark.
After each run the benchmark checked that the node, the model position, the connection
end points and the z value are correct. All runs passed this check on both builds.

Breaking changes?

No. No API or ABI change.

Related issue

None.

🤖 Generated with Claude Code

The scene moves the node when the model reports the new position.
itemChange() then moves the connections of the node.
mouseMoveEvent() moved them a second time, so each connection was
moved and repainted twice per mouse move.

The test counts the connection lookups for one mouse move. It also
checks that the connection follows the node before the release.
hoverEnterEvent() lowers the raised items that overlap the node. It
called collidingItems(), which tests the shape of every overlapping
item. A node always overlaps its own connections, so each hover built
the stroke of every connection of the node.

Only items with a z value above 0 can change. The loop now checks the
z value first and runs the shape test only for those items.
Connections have a z value below 0, so they build no stroke. The set
of lowered items is the same as before.

One test checks that a hover builds no connection stroke. A second
test checks which items a hover lowers and which it keeps.
@paceholder

Copy link
Copy Markdown
Owner

Thank you for the change. master moved since you opened this pull request, and the branch conflicts with it. The conflict is only the list of test files in test/CMakeLists.txt: another pull request (#575) added entries at the same place as yours. The source file merges without changes.

To save you a round trip, we rebased your two commits on the current master and pushed them from a branch in this repository: #578. The commits are unchanged, and you are still the author of both. The whole test suite passes on the rebased branch (114 test cases, with your 3 new tests).

We will merge #578. This pull request stays open until then, and we will close it when #578 is merged.

We checked the hover change on a scene with 5000 nodes. The new loop does not grow with the size of the scene (0.035 ms, against 36 ms for the old collidingItems() loop). Good work.

@paceholder

Copy link
Copy Markdown
Owner

Your two commits are merged into master through #578 (ab07f68 and cd0051c), with you as the author. We close this pull request because #578 replaces it. Thank you for the change.

@paceholder paceholder closed this Dec 2, 2026
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.

2 participants