should use Gtk.TreeSortable.set_sort_func and os.scandir
multiSnow opened this issue · comments
After 43d93a9, file/directory added by Gio.FileMonitor
will not be sorted and always appeared at the top of list because 'Gtk.TreeSortable.set_sort_func' is not used in file list.
And, the 'freeze' of #415 is not mainly caused by the 'sorting', but buy the 'rendering list with thousands of entries in one frame`.
os.scandir should be used in python3 instead of 'os.listdir', and 'Gtk.TreeSortable.set_sort_func' should be set before 'os.scandir' started.
In this way, GUI only need to do with only one entry each time and directly render it at the sorted place, and could be interrupted by user.
It could be done by adding a new backend and API, or simply remove 'os.listdir' and let 'os.scandir' use same API hich is used by 'Gio.FileMonitor', but, anyway, 'Gtk.TreeSortable.set_sort_func' is required.
Large majority of the delay was indeed caused by the custom sort function. Simply put Python is slower than a sort algorithm implemented in C. Granted ours was way better in terms of order, but speed is not even comparable. Added to that we can not simple use os.scandir
or listdir
because those methods don't really support anything else other than local file systems. For that we have providers which implement those methods. As you can see LocalProvider
implements listdir
. The fact scandir
is faster I didn't know. We should definitely look into it however I'd like to give Gio a shot with its directory listing iterator.
Issue you are describing, where new items or changed items are placed above parent directory link is known to me. I noticed it today and solution to that is quite easy. After adding new item all we need to do is call generate_sort_data
for only one item.
New approach of dedicating a single string column, which is hidden, for sorting purposes is much better when it comes to performance while offering wider range of possibilities at the expense of slightly higher memory usage. Going back to defining custom sort function and applying it per column while setting and resetting is inferior approach in almost every sense. Also the reason why new items show on top is because value for this sort column is empty when new item is added, not that sort is not working.