Skip to content

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

Merged
paceholder merged 2 commits into
masterfrom
perf-node-drag-and-hover
Dec 2, 2026
Merged

paceholder merged 2 commits into
masterfrom
perf-node-drag-and-hover

Conversation

@paceholder

Copy link
Copy Markdown
Owner

Type of change

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

Description

This is #571 by @Doome161, rebased on the current master. The two commits are unchanged, and the author is kept. The only conflict was the list of test files in test/CMakeLists.txt: #575 and #571 both add entries at the same place. The source file merged without changes.

Two performance fixes in NodeGraphicsObject:

  1. Move the connections of a dragged node once per mouse move. The scene moves the node when the model reports the new position, and itemChange() then moves the connections. mouseMoveEvent() moved them a second time, so each connection was moved and repainted twice per mouse move. The group branch is unchanged.
  2. Test only raised items for overlap when a node is hovered. hoverEnterEvent() called collidingItems(), which tests the shape of every overlapping item, and a node always overlaps its own connections. Now the z value is checked first, and the shape test runs only for raised items. The set of lowered items is the same as before.

The timings of the author are in #571 (a drag of one node with 50 connections: about 50 % less time; a hover: 99 % less). I did not repeat that benchmark. What I measured myself, for the loops alone and without painting: with 5000 nodes (about 10000 items) the old hover loop took 36 ms and the new one 0.035 ms, and the new loop does not grow with the size of the scene.

Testing

  • Qt version tested: 6.12 (offscreen). CI covers Qt 5 and MSVC.
  • Existing tests still pass. On the rebased branch: 114 test cases, 1044 assertions (the 111 of master plus the 3 new tests of the author).
  • Added tests for new functionality, by the author: one drag moves the connections once per mouse move (with grouping on and off), hovering builds no connection strokes, and hovering lowers the same raised items as before.

Not tested: Qt 5, Linux, Windows. I did not build each of the two commits on its own.

Breaking changes?

No API or ABI change.

Related issue

Replaces #571.

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
paceholder merged commit cd0051c into master Dec 2, 2026
5 checks passed
@paceholder
paceholder deleted the perf-node-drag-and-hover branch December 2, 2026 19:59
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