-
Notifications
You must be signed in to change notification settings - Fork 0
[Performance] How to improve lags #203
Description
I'm collecting here some experiments I made to improve the lag between the pointer position and the actual tool. The lag can be demonstrated by just moving a large eraser over the board, even with no mouse button pressed. Even with medium speed the circle lags remarkably behind the eraser cursor.
The main reason is the low rate of mouse move events in these situations. The rate drops from 7 ms to 33 ms when we do some processing in the event handler. This was not the case with Qt 5.
My first try was just to drop the emit painted() call in the UBBoardView, which triggers thumbnail updates. This increases the repetition rate of the events at least to 16 ms. We still did not get the 7 ms of Qt 5.
I then tried to implement a simple PoC: just a simple application with a QGraphicsView which draws lines and moves a circle on a scene when the mouse button is pressed. Here I get the fast repetition rates of 7 ms even in Qt 6.
The next experiment was to reintroduce the live thumbnails using a QGraphicsView. This was not too difficult to implement on top of refactor-unified-thumbnails, but with this I again was back at 33 ms, so there was no performance difference to the pure pixmap approach.
CPU usage for the main thread was about 25% at max, both for Qt 5 with 7 ms and Qt 6 with 33 ms. So the CPU is not the throttling factor.
The numbers for the time between mouseMove events of 7.7 ms, 16.6 ms and 33.3 ms seems to follow a rule and are roughly doubling. For me this looks like some event throttling, where only each second or fourth event is propagated.
I was also measuring the time for mouseMoveEvent processing. It was about 20 to 65 µs.
I also started a thread in the Qt forum: https://forum.qt.io/topic/160602/frequency-of-mousemoveevents-lower-with-qt-6