https://bugs.kde.org/show_bug.cgi?id=529250

            Bug ID: 529250
           Summary: UI freezes for seconds when selecting/displaying an
                    image while DatesJob runs:
                    CoreDB::getAllCreationDates() converts every item's
                    date via QDateTime::fromString()/mktime (tzset) under
                    the Core DB lock (~25 s for 100k items)
    Classification: Applications
           Product: digikam
      Version First 9.1.0
       Reported In:
          Platform: Ubuntu
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: Database-Scan
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

digiKam bug report — draft (for bugs.kde.org)
Suggested fields:
Product: digiKam
Component: Database (adjust if a better component exists)
Version: 9.1.0 (also reproduced on 9.0.0)
Platform: Ubuntu 26.04.1 LTS, x86-64
Title
UI freezes for seconds when selecting/displaying an image while DatesJob runs:
CoreDB::getAllCreationDates() converts every item's date via
QDateTime::fromString()/mktime (tzset) under the Core DB lock (~25 s for 100k
items)
Summary
With a collection of roughly 100,000 items, digiKam's DatesJob takes about
25–27 seconds per run. It runs at startup and again after collection changes
(e.g. after deleting items). While it runs, selecting or displaying an image
in the main window freezes the UI for seconds (up to ~10 s observed), because
the GUI thread blocks on the Core DB access lock in
Digikam::DisjointMetadata::load() while DatesJob holds the database busy
converting dates.
Backtraces (taken with gdb during a freeze, on two different versions) show
the busy thread inside:
    Digikam::DatesJob::run()
      -> Digikam::CoreDB::getAllCreationDates()
        -> QVariant::toDateTime()
          -> QDateTime::fromString()
            -> qMkTime() -> mktime -> tzset (parsing "JST-9")
i.e. every item's creation-date string is converted one by one through the
local-timezone machinery (system timezone is Asia/Tokyo, "JST-9"), instead of
being parsed in UTC or with a cached timezone. This looks like the same class
of problem as bug 477853, but it still reproduces with digiKam 9.1.0 and its
bundled Qt 6.11.0.
Environment
OS: Ubuntu 26.04.1 LTS (x86-64), timezone Asia/Tokyo
digiKam 9.0.0 (Ubuntu apt package, system Qt 6) — reproduced
digiKam 9.1.0 (official Qt6 AppImage, bundled Qt 6.11.0) — reproduced
Database: SQLite, WAL mode enabled, database files on a local SSD
  (schema 16 on 9.0.0, migrated to 17 on 9.1.0)
Photo files on an internal HDD (not the bottleneck: the freeze is CPU/lock
  bound, one core at ~100%, and also occurs with test data on SSD)
Collection size: ~100,000 items
Steps to reproduce
Use a collection of ~100,000 items (SQLite backend).
Start digiKam, or perform a collection change that re-triggers the dates
   job (e.g. select a batch of images and delete them).
While DatesJob is running (about 25 s), click on images to select/display
   them.
A reliable manual trigger: delete a batch of images, then immediately start
clicking through images.
Actual results
The UI freezes for seconds when an image is selected/displayed while
  DatesJob runs.
The frozen image is random; displaying the same image again afterwards is
  fast. Closing the sidebar and the preview does not help.
One CPU core is at ~100% during the freeze; no background progress is
  shown in the UI.
Measured DatesJob durations (from the debug log,
"One job is done Digikam::DatesJob ... time: N"):
9.0.0: 25189 ms, 25016 ms
9.1.0 (test copy of the DB): 24727 ms, 24594 ms, 24885 ms
9.1.0 (production DB, one session): 25358 ms, 26604 ms, 26824 ms
  (three runs in a single session: startup + two re-runs; 24 DeleteJobs
  preceded the third run)
Expected results
Date statistics computation should not block image selection/display:
  either the per-item date conversion should be fast (parse as UTC / cache
  the timezone instead of per-item mktime+tzset), or getAllCreationDates()
  should not hold the Core DB lock for its whole duration, or the dates data
  should be updated incrementally instead of recomputed in full after every
  collection change.
Backtrace — digiKam 9.1.0 (AppImage, Qt 6.11.0), during a freeze
Busy thread (DatesJob):
Thread 2:
#0  __memcmp_avx2_movbe () at
../sysdeps/x86_64/multiarch/memcmp-avx2-movbe.S:171
#1  __tzstring_len (s=0x... "JST-9", len=3) at ./time/tzset.c:93
#2  parse_tzname (tzp=..., whichrule=0) at ./time/tzset.c:176
#3  __tzset_parse_tz (tz=...) at ./time/tzset.c:328
#4  __tzfile_compute (timer=1183442136, use_localtime=1, ...) at
./time/tzfile.c:635
#5  __tz_convert (timer=1183442136, use_localtime=1, ...) at ./time/tzset.c:580
#6  convert_time (convert=<__localtime_r>, ...) at ./time/mktime.c:261
#7  ranged_convert (...) at ./time/mktime.c:275
#8  __mktime_internal (...) at ./time/mktime.c:471
#9  qMkTime(tm*) () from libQt6Core.so.6
...
#15 QDateTime::QDateTime(QDate, QTime, QTimeZone const&,
QDateTime::TransitionResolution) () from libQt6Core.so.6
#16 QDateTime::fromString(QStringView, Qt::DateFormat) () from libQt6Core.so.6
...
#19 QVariant::toDateTime() const () from libQt6Core.so.6
#20 Digikam::CoreDB::getAllCreationDates() const () from
libdigikamdatabase.so.9.1.0
#21 Digikam::DatesJob::run() () from libdigikamdatabase.so.9.1.0
GUI thread (blocked on the Core DB lock while loading the selected item):
Thread 1 (main thread, "digikam"):
#0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
#1  QBasicMutex::lockInternal() () from libQt6Core.so.6
#2  QRecursiveMutex::tryLock(QDeadlineTimer) () from libQt6Core.so.6
#3  Digikam::CoreDbAccess::CoreDbAccess() () from libdigikamdatabase.so.9.1.0
#4  Digikam::DisjointMetadata::load(Digikam::ItemInfo const&) () from
libdigikamgui.so.9.1.0
...
#11 QTimer::timeout(QTimer::QPrivateSignal) () from libQt6Core.so.6
Backtrace — digiKam 9.0.0 (apt), during a freeze (same pattern)
Thread 2:
#0  __GI_____strtoul_l_internal (...) at ../stdlib/strtol_l.c:546
...
#4  parse_offset (tzp=..., whichrule=0) at ./time/tzset.c:207
#5  __tzset_parse_tz (tz=...) at ./time/tzset.c:328
#6  __tzfile_compute (timer=1089645154, use_localtime=1, ...) at
./time/tzfile.c:635
#7  __tz_convert (...) at ./time/tzset.c:580
...
#11 qMkTime(tm*) () from libQt6Core.so.6
...
#18 QDateTime::fromString(QStringView, Qt::DateFormat) () from libQt6Core.so.6
...
#21 QVariant::toDateTime() const () from libQt6Core.so.6
#22 Digikam::CoreDB::getAllCreationDates() const () from
libdigikamdatabase.so.9.0.0
#23 Digikam::DatesJob::run() () from libdigikamdatabase.so.9.0.0

Thread 1 (main thread):
#1  QBasicMutex::lockInternal() () from libQt6Core.so.6
#2  QRecursiveMutex::tryLock(QDeadlineTimer) () from libQt6Core.so.6
#3  Digikam::CoreDbAccess::CoreDbAccess() () from libdigikamdatabase.so.9.0.0
#4  Digikam::DisjointMetadata::load(Digikam::ItemInfo const&) () from
libdigikamgui.so.9.0.0
Additional information
Possibly related: KDE bug 477853 (slow collection of date information due
  to timezone conversion in QDateTime handling) and QTBUG-120285 (Qt
  timezone cache). Despite those, the freeze still reproduces on 9.1.0 /
  Qt 6.11.0 as shown above.
Full backtraces (all threads) and debug logs from both versions are
  available and can be attached on request.
Migrating the database to MariaDB was considered but not attempted: the
  bottleneck is client-side date conversion plus lock contention, not SQL
  throughput.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to