[KPhotoAlbum] Big performance problem with QDateTime

Robert Krawitz rlk at alum.mit.edu
Sun Sep 20 15:14:26 BST 2020


Certain kpa operations, in particular startup and home (i. e. select all images) appear to have
slowed down drastically recently.  The problem is in the XMLImageDateCollection code; specifically,
building the map between date and DB::ImageDate is very slow (the home operation is taking about 25
seconds on my system).  This is done once at startup and whenever the selected set changes, for the
date bar.

The problem is that QDateTime comparisons, which need to be done extensively for map insertions, are
very slow because to correctly handle timezone and DST issues the date/time has to be converted to
milliseconds since the epoch.  But there have been reports of this issue for quite a while
(https://bugreports.qt.io/browse/QTBUG-41714), and apparently it's something that upstream can't or
won't fix, and I would definitely have noticed this earlier.  I suspect something has changed in the
default behavior, possibly related to when I upgraded my laptop.  Perhaps the linear time stamp had
previously been cached and isn't now.

There's a local fix to the datebar issue, namely use the time since the epoch as the key rather than
the QDateTime itself.  This results in the home operation now taking a second or two.  Even so, the
conversion to milliseconds is taking about 73% of the total time of that operation.  For reference,
the conversion had been done about 2.5E+07 times previously; it's now being done about 1E+06 times
(with 380K images in my database).  It also accounts for about 15% of the startup time, with the
conversion being done about 1.4E+07 times (4 times per image).

The fix really needs to be in QDateTime, to cache this.  I don't want to rewrite every use of
QDateTime in kpa, but this one case (see attached patch) clears up the most egregious behavior.

There's an existing bug against Qt (https://bugreports.qt.io/browse/QTBUG-75585) about this that got
closed, but I'm going to comment on it and maybe open a new one.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: datebar-performance.patch
Type: text/x-patch
Size: 4457 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kphotoalbum/attachments/20200920/001e1c4b/attachment.bin>


More information about the Kphotoalbum mailing list