Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-81690

QSortFilterProxyModel handles insertions very inefficiently

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.14.0
    • Fix Version/s: None
    • Component/s: Core: Item Models
    • Labels:
      None
    • Platform/s:
      Windows

      Description

      When profiling why batch-inserting a few thousand elements to a source model that already contains e few 100k elements causes very large delays (~10s) in QSortFilterProxyModel I found that inserts are handled very inefficiently:

      • First the batch is split into separate inserts at the sorted positions (this is unavoidable)
      • Then for each insert, the elements are inserted into the proxy model
      • Then the reverse map is updated

      It is the last step that causes almost 100% of the CPU time. The reason is that it always completely discards the reverse mapping and re-builds it from scratch, see https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/itemmodels/qsortfilterproxymodel.cpp#n918

      Since it is perfectly known at that point, what has been inserted, the reverse mapping can be updated much more efficiently, by just inserting these elements. The same is probably true in other places where build_source_to_proxy_mapping  is used...

      See the attached profiler screenshot in order to appreciate how bad this really is. It makes the QSortFilterProxyModel utterly useless for our use-case...

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            dfaure_kdab David Faure
            Reporter:
            mika.fischer Mika Fischer
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes