Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.14.0
-
None
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...