OmixVisualization / qtjambi

QtJambi is a wrapper for using Qt in Java.
http://www.qtjambi.io
Other
365 stars 43 forks source link

Decreasing UI performance of QListView #135

Closed sircodalotkob closed 1 year ago

sircodalotkob commented 1 year ago

We experience that the UI performance of a QListView continuously decreases as we interact with it.

Issue #125 already tackled a problem with QModelIndex. We suspect our issue to be related as interacting with a QListView means a lot of calls to its model with QModelIndex as parameter.

To Reproduce

In order to demonstrate the performance leak, we need to display a QListView and have it call its model very often:

  1. Launch the following test application.
  2. Maximize the window so that many rows are visible.
  3. Grab the scrollbar thumb and repeatedly scroll the list from top to bottom and back.
  4. After a while, the scrolling will get choppier and choppier.
package test;

import io.qt.core.QAbstractListModel;
import io.qt.core.QModelIndex;
import io.qt.core.Qt.ItemDataRole;
import io.qt.widgets.QApplication;
import io.qt.widgets.QListView;

public class Test {

    static class TestListModel extends QAbstractListModel {

        private static final int SIZE = 1000;

        @Override
        public int rowCount(QModelIndex index) {
            return SIZE;
        }

        @Override
        public Object data(QModelIndex index, int role) {
            if (role == ItemDataRole.DisplayRole) {
                return "Item " + index.row();
            }
            return null;
        }

    };

    public static void main(String[] args) {

        QApplication.initialize(args);

        QListView list = new QListView();
        list.setWindowTitle("QListView");
        list.setModel(new TestListModel());
        list.show();

        int result = QApplication.exec();

        QApplication.shutdown();

        System.exit(result);

    }

}

Expected behavior

The UI performance of a QListView should not decrease even after many interactions with the widget.

System

Additional information

We took it to the extreme and kept scrolling the QListView until the widget updates took almost a second. The CPU was hogged during those updates.

We ported the test application to Python using PySide6 and also to native C++ code. In both cases, the QListView didn't show the described decline of performance.

omix commented 1 year ago

Thanks for letting me know. This is extremely helpful.

sircodalotkob commented 1 year ago

We consider creating a desktop app using QtJambi, but this potential performance leak is an element of uncertainty for us. That's why we did some more tests in order to get a hunch of what the problem might be.

We altered the test application above a bit and now have two instances of QListView beside each other.

The problem seems to be closer to the model and the model index classes than to the widgets classes.

One possible reason for things getting continuouly slower might be some container class accidentically accumulating temporary or short-lived object so that the object retrieval time grows.

omix commented 1 year ago

This issue is specific for latest release version. I decided to replace the previous lightweight implementation of QModelIndex by a generated one. Here, the lifecycle of QModelIndex depends on its model. This dependency causes this performance issue. The algorithm is too inefficient to handle hundredthousands of dependencies.

I already ficed this issue. It will be available in the next release version. I hope to make it available within the next two weeks.

omix commented 1 year ago

If you want to convince yourself from using QtJambi for a desktop app, please take a look at Omix. Omix is a domain specific drawing tool from the size of powerful office applications. It is completely written in Java with QtJambi. The entire drawing engine is based on Qt's graphics view (which was state of the art in 2007 where the project began). It also provides model view for showing large tabular data. Feel free to download and test the tool: www.omix-visualization.com

mchistovib commented 1 year ago

@sircodalotkob could you please have a look at it now with Jambi 6.4.4?

omix commented 1 year ago

I'm closing this as being solved. @sircodalotkob if you have further questions don't hesitate to contact me directly via email.

sircodalotkob commented 1 year ago

@sircodalotkob could you please have a look at it now with Jambi 6.4.4?

@mchistovib The issue doesn't seem to occur with Jambi 6.4.4 anymore.

I'm closing this as being solved. @sircodalotkob if you have further questions don't hesitate to contact me directly via email.

@omix Thank you very much.