Skip to content

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

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

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

Conversation

@Doome161

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,
median of 3 interleaved rounds of 7 samples each. Grouping off. The connection painter
strokes the cubic once.

Scenario N master (ms) this PR (ms) Change
Drag, 1000 mouse moves 1 14.2 8.8 -38 %
Drag 10 108.2 57.4 -47 %
Drag 50 547.9 276.9 -50 %
Hover, 1000 enter/leave pairs 1 3.6 0.5 -86 %
Hover 10 45.2 0.5 -99 %
Hover 50 364.0 0.8 -99.8 %

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.
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.

1 participant