viewer icon indicating copy to clipboard operation
viewer copied to clipboard

Opening an image in a directory with many files is very slow

Open jonnykl opened this issue 2 months ago • 1 comments

Describe the bug When opening an image in a directory with many (~10k) images, my browser hangs for about a minute. The longest time seems to be consumed by https://github.com/nextcloud/viewer/blob/c77de0393c22dbd294d6006d7ee4209e3c81d74d/src/views/Viewer.vue#L797-L799

The map() call here has a runtime complexity of O(n^2) with n being the number of files in the directory which is not ideal.

If I don't overlook something, the goal of https://github.com/nextcloud/viewer/blob/c77de0393c22dbd294d6006d7ee4209e3c81d74d/src/views/Viewer.vue#L778-L799 is to get filteredFiles sorted and assign that to this.fileList.

From an algorithmic point of view, it should be possible that sortNodes() (or a similar function) returns a list of indices that sort the underlying list (here nodes) like argsort in NumPy. Then this list of indices can be used to reorder filteredFiles. Then, except for the sorting everything should run in O(n).

To Reproduce Steps to reproduce the behavior:

  1. Open an image in a directory with many (~10k) images
  2. Wait until the prev/next buttons appear

Desktop (please complete the following information):

  • OS: Ubuntu 22.04
  • Browser Firefox 144.0.2

jonnykl avatar Nov 10 '25 11:11 jonnykl

Should be fixed once we have #2989

skjnldsv avatar Nov 26 '25 08:11 skjnldsv