Skip to content

Optimize large folder listing, filtering, sorting, and scrolling - #217

Merged
dhh merged 2 commits into
mainfrom
optimize-large-folders
Nov 23, 2026
Merged

dhh merged 2 commits into
mainfrom
optimize-large-folders

Conversation

@dhh

@dhh dhh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Speeds up browsing, filtering, searching, sorting, expanding, selecting, and scrolling large folders (10,000+ entries).

Changes

  • POSIX directory traversal & MIME caching (src/foldermodel.h, src/foldermodel.cpp):
    • Replace QDirIterator/QFileInfo in list() with opendir/readdir/fstatat, UTC QDateTime timestamps (avoiding per-file localtime_r), a thread-local kindForMime() cache, and a globs2-aware per-thread single-extension MIME cache (falling back to QMimeDatabase for literal filenames, compound extensions, and special globs).
    • Replace itemCount() and summarize() with single-pass opendir/readdir (no stat(), no sorting all filenames to find the first two pictures).
    • Use opendir/readdir + d_type in search() to skip stat() on non-matching files, with std::deque for BFS traversal.
    • Pre-compile chooser filters (CompiledFilter, cached thread-locally in fits()) so filename globs and MIME inheritance aren't recomputed per file.
    • Compute QCollatorSortKey lazily on ties for modified, oldest, size, and kind sorts, and cache unique extension keys.
  • Model scalability (src/foldermodel.h, src/foldermodel.cpp):
    • Add an O(1) lazy m_pathIndex hash for indexOfPath().
    • Replace the O(R·N) per-item insert loop in setExpanded() with a single O(N + R) range insert.
    • Emit targeted dataChanged ranges in setSelected() and coalesce contiguous dataChanged ranges in countFolders().
  • View scrolling, selection & GPU masks (src/FileListView.qml, src/FolderGrid.qml, src/FolderList.qml, src/Band.qml, src/FileRow.qml, src/FileTile.qml, src/Format.js):
    • Enable reuseItems: true in FileListView (covering Columns as well as List) and FolderGrid (resetting drag pictures on GridView.onReused).
    • Scope Band.qml hit-testing to the visible index range overlapping the selection rectangle instead of scanning all items on every mouse move.
    • Gate rowMask and thumbMask offscreen layer.enabled on thumb.layer.enabled to avoid allocating FBO textures for rows/tiles without rounded thumbnails.
    • Cache Qt.locale() in Format.js and translate only the single unit needed in Format.size().

Benchmarks

Measured on a 10,100-entry folder (10,000 files across 12 extensions + 100 folders), Release builds:

Benchmark Before After Speedup
FolderModel::list() (name) 209.64 ms 19.62 ms 10.7×
FolderModel::list() (modified) 208.36 ms 19.15 ms 10.9×
FolderModel::list() (size) 210.24 ms 19.04 ms 11.0×
FolderModel::list() (kind) 211.82 ms 21.50 ms 9.9×
FolderModel::sortEntries() (name) 10.08 ms 4.08 ms 2.5×
FolderModel::sortEntries() (modified/size) 9.87–10.56 ms 3.82–3.83 ms 2.7×
FolderModel::sortEntries() (kind) 17.64 ms 5.93 ms 3.0×
FolderModel::itemCount() 11.18 ms 1.76 ms 6.4×
FolderModel::summarize() 18.26 ms 2.07 ms 8.8×
FolderModel::search() ("999") 14.81 ms 3.05 ms 4.9×
FolderModel::fits() (3 globs) 664.09 ms 2.31 ms 287×

@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the added tests address the previous finding.

Summary

Speeds up large-folder browsing through faster directory reads, cached MIME checks, fewer model updates, and reused rows and tiles.

  • Folder listings reuse file details, filters, and sorting work.
  • Folder searches check fewer file details before finding matches.
  • Folder counts and preview pictures come from one directory pass.
  • Folder paths and expanded rows take fewer model operations.
  • Folder views reuse scrolled items and limit selection checks.
  • Thumbnail masks use layers only when thumbnails need them.
  • Date labels reuse locales and size labels translate one unit.

Reviews (2) · Last reviewed commit: "Add test verifying list() matches entryF..." · Reviewed by Greptile

Comment thread src/foldermodel.cpp Resolved
@dhh
dhh merged commit ad777f5 into main Nov 23, 2026
2 checks passed
@dhh
dhh deleted the optimize-large-folders branch November 23, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant