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

[Regr:6.5->6.6] QDateTime comparison performance regression on macOS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.5.4, 6.6.1, 6.7.0 FF
    • 6.6.0
    • Core: Date/Time
    • None
    • macOS Ventura 13.5.2
      MacBook Pro M1 Max 64 GB
    • macOS
    • 2
    • be55fbede (dev), f5760cd7c (6.6), 270011ddb (tqtc/lts-6.5)
    • Foundations Sprint 94

    Description

      We noticed a significant drop in performance when comparing QDateTime values with a default value that is the minimum date for SQL server (1/1/1753). Some experimentation showed that all dates greater than 1900 perform fine but anything lower than that is quite a bit slower.

      The following benchmark does the comparison with a bunch of random QDateTime/timezone combinations.
      On my M1 Max MacBook Pro it has the following results:

      • Qt 6.5.3: 6.017 msecs per iteration
      • Qt 6.6.0: 10,822 msecs per iteration
      bench.cpp
      #include <QTest>
      #include <QDateTime>
      #include <QTimeZone>
      
      class DateTimeBenchmark : public QObject{
      	Q_OBJECT
      private slots:
      	void equal();
      };
      
      void DateTimeBenchmark::equal()
      {
      	constexpr int iterations = 1000;
      	constexpr int listSize = 100;
      
      	QVector<QDateTime> list;
      	list.reserve(listSize);
      
      	// Init each list entry with random time within the next 60 days and random time zone
      	const QDateTime start = QDateTime::currentDateTime();
      	const QDateTime end = QDateTime::currentDateTime().addDays(60);
      	const auto availableTimeZones = QTimeZone::availableTimeZoneIds();
      
      	std::srand(12345);
      	for(int i = 0; i < listSize; ++i)
      	{
      		QDateTime dateTime = start.addMSecs(std::rand() % start.msecsTo(end));
      		QTimeZone timeZone{availableTimeZones.at(std::rand() % availableTimeZones.size())};
      		dateTime.setTimeZone(timeZone);
      		list.push_back(dateTime);
      	}
      
      	// Minimum date for SQL server
      	QDateTime emptyQDateTime{QDate{1753, 1, 1}, QTime{0, 0, 0, 0}};
      
      	QBENCHMARK {
      		for(int iter = 0; iter < iterations; ++iter)
      		{
      			for(const auto& t : list)
      			{
      				bool result = t == emptyQDateTime;
      				Q_UNUSED(result);
      			}
      		}
      	}
      }
      
      QTEST_GUILESS_MAIN(DateTimeBenchmark);
      
      #include "bench.moc"
      

      Most of the time is spent comparing the time zone where lots of temporary memory is allocated/deallocated and conversions to NSString are made.

      Attachments

        Issue Links

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

          Activity

            People

              Eddy Edward Welbourne
              lbuckel Leon Buckel
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes