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

            Bug ID: 528607
           Summary: Sort by Size keeps one CPU core busy after a file
                    outside the thumbnail range changes
    Classification: Applications
           Product: dolphin
      Version First 25.04.3
       Reported In:
          Platform: Debian stable
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: view-engine: general
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
  Target Milestone: ---

SUMMARY
With Sort by Size and thumbnails enabled, changing the modification time of a
file outside the thumbnail range can leave Dolphin continuously sorting at
approximately 100% of one logical CPU.

STEPS TO REPRODUCE
1. Create a folder with 1,600 equally sized files and one subfolder:

   dir=$(mktemp -d)
   mkdir "$dir/subfolder"
   for i in $(seq -w 0 1599); do touch "$dir/item-$i.txt"; done
   dolphin --new-window "$dir"

2. Enable thumbnails, sort by Size ascending, and stay at the top of the
folder. Let Dolphin settle.
3. In the same shell, run: touch -m "$dir/item-0900.txt"

OBSERVED RESULT
Dolphin went from idle to approximately 100% of one logical CPU and stayed busy
after the folder stopped changing. Switching to Name sort returned it to idle.

EXPECTED RESULT
Dolphin returns to idle after processing the change. The file's thumbnail can
be refreshed when it comes into range.

SOFTWARE/OS VERSIONS
Dolphin: 25.04.3 (stock Debian package 4:25.04.3-1+deb13u1)
Operating System: Debian 13
KDE Plasma: 6.3.6
KDE Frameworks/KIO: 6.13.0
Qt: 6.8.2

ADDITIONAL INFORMATION
Representative GDB frames from the stock executable while it was busy
(intermediate frames omitted):

    DolphinView::directorySortingProgress(int)
    KFileItemModel::directorySortingProgress(int)
    KFileItemModelRolesUpdater::resolveNextSortRole()
    QObject::event(QEvent*)

Other samples repeatedly reached KFileItemModelRolesUpdater::startUpdating().
The changed item remains in m_changedItems after its sort role is processed.
Because indexesToResolve() omits it from the next thumbnail batch, no thumbnail
callback consumes the entry. When the batch ends, updateChangedItems() queues
the same sort work again.

The patch below consumes the entry in the sort queue and invalidates the
finished item so scrolling can still trigger a refresh. The same reproduction
stayed idle on the locally patched 25.04.3 build. In the regression test, the
old library emitted 2,706 sort-progress notifications in 250 ms. The patched
library emitted one, and the test verified that scrolling the item into range
still resolved its thumbnail role.

Related: bug 509081 reports a similar symptom when sorting by size or
modification time. This report describes the reproducible off-screen file
change case.

Proposed patch for 25.04.3:

--- a/src/kitemviews/kfileitemmodelrolesupdater.cpp
+++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp
@@ -733,9 +733,17 @@
         const KFileItem item = *it;
         const int index = m_model->index(item);

+        // Consume the change after taking it from the sort queue. The
remaining
+        // roles are refreshed when startUpdating() schedules the item. It may
+        // be outside that batch, so waiting for a preview would repeat
sorting.
+        const bool changed = m_changedItems.remove(item);
+        if (changed) {
+            m_finishedItems.remove(item);
+        }
+
         // Continue if the sort role has already been determined for the
         // item, and the item has not been changed recently.
-        if (!m_changedItems.contains(item) &&
m_model->data(index).contains(m_model->sortRole())) {
+        if (index < 0 || (!changed &&
m_model->data(index).contains(m_model->sortRole()))) {
             it = m_pendingSortRoleItems.erase(it);
             continue;
         }

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

Reply via email to