cosmic-files/docs/local-performance-and-portal-notes.md
Votre Nom 338354c4d0 Improve initial directory listing latency
Avoid synchronous child counts during item construction, use extension-based MIME detection for initial scans, and defer expensive MIME icon resolution by using generic file icons for ordinary files. Document the local xdg-desktop-portal FileChooser workaround for COSMIC portal crashes.
2026-05-05 08:00:08 +02:00

2.7 KiB

Local performance and portal notes

Date: 2026-05-05

This repository carries a local patch aimed at improving initial directory display latency in large folders, plus a system-level workaround for a COSMIC portal FileChooser crash observed with Firefox and Chromium.

Directory listing latency

The slow path was the initial construction of Item values in src/tab.rs. On a test folder with about 2000 entries, raw filesystem enumeration and stat calls completed in a few milliseconds, while COSMIC Files took multiple seconds before showing the directory.

The local patch keeps initial item construction cheap:

  • directory child counts are no longer computed synchronously in item_from_entry and item_from_gvfs_info;
  • initial MIME detection uses extension-based mime_guess;
  • regular files use a generic file icon during the initial scan instead of resolving the full MIME icon immediately.

This keeps folders and .desktop files special-cased, while avoiding expensive per-file work for ordinary files during first paint.

Measured locally during investigation:

  • before the MIME/icon changes: about 3.1 seconds for ~/Téléchargements;
  • after avoiding full MIME icon resolution during scan: below the temporary 100 ms perf-log threshold for the same folder.

File chooser portal workaround

Firefox and Chromium were failing to open Save As on the first attempt because xdg-desktop-portal-cosmic crashed while handling FileChooser.

Logs showed:

Backend call failed: Remote peer disconnected
xdg-desktop-portal-cosmic ... status=11/SEGV

The working local system workaround is to remove org.freedesktop.impl.portal.FileChooser from:

/usr/share/xdg-desktop-portal/portals/cosmic.portal

so the file chooser falls back to GTK. The resulting local cosmic.portal keeps COSMIC for the other interfaces:

[portal]
DBusName=org.freedesktop.impl.portal.desktop.cosmic
Interfaces=org.freedesktop.impl.portal.Access;org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.Settings;org.freedesktop.impl.portal.ScreenCast
UseIn=COSMIC

Backups created locally:

/usr/share/xdg-desktop-portal/portals/cosmic.portal.bak-codex-20260505-filechooser
/usr/share/xdg-desktop-portal/cosmic-portals.conf.bak-codex-20260505
/usr/share/xdg-desktop-portal/cosmic-portals.conf.bak-codex-20260505-2

After editing portal files, restart:

systemctl --user restart xdg-desktop-portal.service xdg-desktop-portal-gtk.service

Package updates may overwrite /usr/share/xdg-desktop-portal/portals/cosmic.portal. If Save As starts needing two attempts again, re-check that FileChooser has not been reintroduced in cosmic.portal.