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

toString() in macOS' system locale is very slow

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.4.1, 6.5
    • Core: Locales (i18n)
    • None
    • macOS
    • 21
    • Foundation PM Prioritized

    Description

      My app, that needs to filter a big table model, is very slow on macOS. Upon investigation, I found out that all QLocale().toString(int/double/QDateTime) are 2-3 orders of magnitude slower than the same calls on QLocale::c().

      Attached is a simple benchmark tool that produces the output below. You'll see that we're currently around 100x slower in release builds (debug builds are around 1000x slower, but a big part of that is the QMacAutoReleasePool in the macOS query() callback).

      Here is a patch on gerrit that adds caching to any QSystemLocale call that returns a constant string: https://codereview.qt-project.org/c/qt/qtbase/+/446822

      Int and enum returns from query() are currently not cached and dynamic data (e.g. QDateTime as parameter to query) cannot be cached at all anyway.

      baseline, dev branch, release build on MacBook Air M2

             Locale: C     10000x toString(3.14): 0s 003ms 069us
             Locale: de_DE 10000x toString(3,14): 0s 003ms 020us
      System Locale: en_DE 10000x toString(3,14): 0s 408ms 052us
             Locale: C     10000x toString(12345): 0s 000ms 331us
             Locale: de_DE 10000x toString(12.345): 0s 000ms 704us
      System Locale: en_DE 10000x toString(12.345): 0s 382ms 285us
             Locale: C     10000x toString(Monday, 5 December 2022 04:05:29 CET): 0s 032ms 768us
             Locale: de_DE 10000x toString(Montag, 5. Dezember 2022 04:05:29 CET): 0s 032ms 779us
      System Locale: en_DE 10000x toString(5. December 2022 04:05:29 CET): 2s 457ms 831us

       

      with caching patch:

             Locale: C     10000x toString(3.14): 0s 003ms 243us
             Locale: de_DE 10000x toString(3,14): 0s 003ms 346us
      System Locale: en_DE 10000x toString(3,14): 0s 005ms 205us
             Locale: C     10000x toString(12345):  0s 000ms 926us
            Locale: de_DE 10000x toString(12.345): 0s 001ms 809us
      System Locale: en_DE 10000x toString(12.345): 0s 002ms 975us
             Locale: C     10000x toString(Monday, 5 December 2022 04:02:32 CET): 0s 047ms 544us
             Locale: de_DE 10000x toString(Montag, 5. Dezember 2022 04:02:32 CET): 0s 032ms 981us
      System Locale: en_DE 10000x toString(5. December 2022 04:02:32 CET): 0s 035ms 714us

       

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-109201
          # Subject Branch Project Status CR V

          Activity

            People

              Eddy Edward Welbourne
              rgriebl Robert Griebl
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes