[Bug] Slow SFTP connections
Cosmic-files version:
0.1.0~12728395411~22.04~c7511bb
Issue/Bug description: Connecting to a network SFTP connection takes a very long time, this seems to scale with the number of files within a directory. Moving between directories also exhibits this behavior. File transfer speed is fine.
Steps to reproduce:
- Connect to a SFTP server.
- Experience long connection time / freeze before it gets added to sidebar.
- Move around in some directories.
- Experience slow load times.
Expected behavior: To have similar performance to connecting via the command line or another file explorer.
Other notes: SFTP connection is running on a non-default port (if that makes any difference at all). I have not tested other file protocols such as samba or normal FTP. The SFTP connection is fast in another file explorer or on the command line.
Running tcpdump on this port while connecting shows a stark difference in packets received when running with cosmic vs another file viewer (in this case I used the default files app on PopOS 22.04). The default file app uses 322 packets and in much shorter timespan. While cosmic uses 823 over a much longer timespan, and the packets appear to be much larger. I don't know if this helps at all.
related: https://github.com/pop-os/cosmic-files/issues/1055
I think I’ve figured out why my SSH connection is slow — it happens when I open a folder and it starts counting the files in each subfolder. One of the folders contains about 138,000 files, which is likely the cause of the delay.
A potential fix would be to mimic how Nautilus handles this: avoid counting the number of files in remote directories upfront. Instead, list the directories immediately and display the file counts asynchronously once they’re available, rather than waiting for the count to finish before showing the contents.