Bug 371515 - Adding new entry is slow
Summary: Adding new entry is slow
Status: RESOLVED FIXED
Alias: None
Product: KBibTeX
Classification: Applications
Component: User interface (show other bugs)
Version: 0.6
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Thomas Fischer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-23 09:05 UTC by Juergen Spitzmueller
Modified: 2016-10-23 13:53 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Proposed fix (1.39 KB, patch)
2016-10-23 09:05 UTC, Juergen Spitzmueller
Details
Updated patch (addressing the mentioned additional issue) (1.62 KB, patch)
2016-10-23 12:45 UTC, Juergen Spitzmueller
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Juergen Spitzmueller 2016-10-23 09:05:21 UTC
Created attachment 101714 [details]
Proposed fix

Especially with the biblatex style, adding a new entry to a database can be extremely slow. It takes up to ~10 seconds until the widget edit dialog finally pops up.

Debugging revealed that the culprit is FileView::setSelectedElement, more precisely the loop over all columns added in https://quickgit.kde.org/?p=kbibtex.git&a=commit&h=4f529a8444e4c

In my case, this loops over all (130!) columns just for the sake of selecting the whole row after the new entry has been added.

I'll attach a patch which uses the QItemSelectionModel::Rows flag instead, which has the same effect but is _much_ faster (the editing window now pops up almost instantaneously).
Comment 1 Juergen Spitzmueller 2016-10-23 11:33:15 UTC
BTW, independent of my patch, the selection of the new entry fails if (1.) the database has comments or macros and (2.) if "Show comments" or "Show macros" is disabled in the prefs. Presumably due to a mismatch of the rows in the file model and the QAbstractItemModel. I had a look but did not find a solution how these can be synchronized.
Comment 2 Juergen Spitzmueller 2016-10-23 12:45:01 UTC
Created attachment 101718 [details]
Updated patch (addressing the mentioned additional issue)

I found the solution to the index mismatching problem: We have to use sortFilterProxyModel()->mapFromSource.

The updated patch does this.
Comment 3 Thomas Fischer 2016-10-23 13:51:42 UTC
Git commit 98e55392df85285a67d628209ac77bd5ed3b071b by Thomas Fischer, on behalf of Juergen Spitzmueller.
Committed on 23/10/2016 at 13:50.
Pushed by thomasfischer into branch 'kbibtex/0.6'.

Speeding up selection of elements

The old code manually iterated over all columns of rows
to be selected, which was expensive in the case of many
columns (e.g. for BibLaTeX) and large files (many rows).

This patch uses a Qt-internal flag when selecting elements
to select the full row with a single call.

Furthermore, the unused function
'setSelectedElement(QList<QSharedPointer<Element> > &)'
has been completely removed as it was unused.

Signed-off-by: Thomas Fischer <fischer@unix-ag.uni-kl.de>

M  +3    -20   src/gui/file/fileview.cpp
M  +0    -1    src/gui/file/fileview.h

http://commits.kde.org/kbibtex/98e55392df85285a67d628209ac77bd5ed3b071b
Comment 4 Thomas Fischer 2016-10-23 13:53:19 UTC
(In reply to Juergen Spitzmueller from comment #2)
> Created attachment 101718 [details]
> Updated patch (addressing the mentioned additional issue)
> 
> I found the solution to the index mismatching problem: We have to use
> sortFilterProxyModel()->mapFromSource.
> 
> The updated patch does this.

Thank you for your bug report and patch!
I was not aware that QItemSelectionModel::Select and QItemSelectionModel::Rows combined have such an effect.
I modified your patch in two ways:
1. Removed setSelectedElements as it is not used anywhere.
2. Made both variables row and idx 'const'.