Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
5.15.2, 6.2.3
-
-
fe7a0c19a (dev)
Description
This is a bug report due to a user report in the forum: https://forum.qt.io/topic/133954
QFileInfo::fileTime() seems to be very slow. This is esp. noticeable when someone tries to sort for e.g. modification time.
After some investigations I found out that it's not directly a QFileInfo issue but the conversion of QDateTime(UTC) to QDateTime(LocalTime) like it's done in QFileInfo::fileTime() since Qt 5.9 due to QTBUG-48306.
Attached a testcase which creates 30k files in a temp directory and then trying to sort after mtime. It's a modified version from the one posted in the forum.
When QDateTime is stored externally and used for sorting, the sorting is reasonable fast (although still not as fast as possible). But when using QFileInfo::fileTime(), the execution is ~300 times slower!
getFileInfos: 76
#files: 30000
myFileInfoList 89
bencMyFileInfo 31
bencQFileInfo 1037
For a test I removed the QDateTime::toLocalTime() call in QFileInfo::fileTime() and got very good results:
getFileInfos: 73
#files: 30000
myFileInfoList 52
bencMyFileInfo 33
bencQFileInfo 62
Looks like QDateTime::toLocalTime() calls some OS functions which in turn call getenv() which costs most of the time according to callgrind/kcachegrind:
Attachments
Issue Links
- relates to
-
QTBUG-108551 Add parameters to QFileInfo's time-stamp methods to configure time-spec and details
- Closed
- resulted from
-
QTBUG-48306 QFileInfo::lastModified is off by 1 hour
- Closed