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

QFileInfo::fileTime() is slow

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.6
    • 5.15.2, 6.2.3
    • Core: Date/Time
    • All
    • 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

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

          Activity

            People

              ahmad.samir Ahmad Samir
              chehrlic Christian Ehrlicher
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes