elementary / photos

Photo viewer and organizer designed for elementary OS
https://elementary.io
GNU Lesser General Public License v2.1
105 stars 38 forks source link

Very slow to open due to reorder of massive tree #649

Open asonix opened 3 years ago

asonix commented 3 years ago

What Happened?

On opening photos, it kicks off a Branch.reorder_all (https://github.com/elementary/photos/blob/master/src/sidebar/Branch.vala#L337), which takes on the order of minutes on my computer to complete. This makes Photos effectively unusable unless I go to make coffee between launching it and starting to use it.

At first, I thought photos was stuck, since it sat consuming 100% CPU on one core for so long and elementary OS launched the "Photos isn't responding" window, but after letting it sit, it eventually finishes.

Steps to Reproduce

  1. Have a very large collection of photos (86GB) neatly organized into folders based on year/month/day/photo
  2. Open photos

Expected Behavior

It should open in a reasonable amount of time

OS Version

6.x (Odin)

Software Version

Compiled from git

Log Output

There's no logs in the path that's taking the time

Hardware Info

Linux firestar 5.11.0-37-generic #41~20.04.2-Ubuntu SMP Fri Sep 24 09:06:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

01:00.0 VGA compatible controller: NVIDIA Corporation GP104 [GeForce GTX 1070] (rev a1)

nvidia-driver-470/focal,now 470.74-0ubuntu0.20.04.1 amd64 [installed]
asonix commented 3 years ago

testing just now, it took 4 minutes and 22 seconds to open photos on my computer (so close to 4:20, dang)

asonix commented 3 years ago

Here's a backtrace when I stop to inspect the current operations:

#0  0x00007ffff74c6fb0 in  () at /lib/x86_64-linux-gnu/libgtk-3.so.0
#1  0x00007ffff74b829c in  () at /lib/x86_64-linux-gnu/libgtk-3.so.0
#2  0x00007ffff74b839e in  () at /lib/x86_64-linux-gnu/libgtk-3.so.0
#3  0x00007ffff7c56802 in g_closure_invoke () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#4  0x00007ffff7c6a962 in  () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#5  0x00007ffff7c75bbe in g_signal_emit_valist () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#6  0x00007ffff7c760f3 in g_signal_emit () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#7  0x00007ffff74c8efc in  () at /lib/x86_64-linux-gnu/libgtk-3.so.0
#8  0x000055555585b644 in sidebar_tree_on_branch_children_reordered (self=0x55555eb9fc40, branch=0x55555dbe1140, entry=0x55555dbe1a50) at ../src/sidebar/Tree.vala:684
#9  0x00005555558565df in _sidebar_tree_on_branch_children_reordered_sidebar_branch_children_reordered (_sender=0x55555dbe1140, entry=0x55555dbe1a50, self=0x55555eb9fc40) at ../src/sidebar/Tree.vala:368
#10 0x00007ffff7c56802 in g_closure_invoke () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#11 0x00007ffff7c6a814 in  () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#12 0x00007ffff7c75bbe in g_signal_emit_valist () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#13 0x00007ffff7c760f3 in g_signal_emit () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#14 0x000055555584f77f in sidebar_branch_children_reordered_callbackPython Exception <class 'ValueError'> Variable 'static_fundamental_type_nodes' not found.: 
 (self=0x55555dbe1140, node=) at ../src/sidebar/Branch.vala:446
#15 0x000055555584e4bf in _sidebar_branch_children_reordered_callback_sidebar_branch_node_children_reordered_callbackPython Exception <class 'ValueError'> Variable 'static_fundamental_type_nodes' not found.: 
 (node=, self=0x55555dbe1140) at ../src/sidebar/Branch.vala:338
#16 0x0000555555850857 in sidebar_branch_node_reorder_childrenPython Exception <class 'ValueError'> Variable 'static_fundamental_type_nodes' not found.: 

    (self=, recursive=1, cb=0x55555584e498 <_sidebar_branch_children_reordered_callback_sidebar_branch_node_children_reordered_callback>, cb_target=0x55555dbe1140) at ../src/sidebar/Branch.vala:185
#17 0x00005555558507fe in sidebar_branch_node_reorder_childrenPython Exception <class 'ValueError'> Variable 'static_fundamental_type_nodes' not found.: 

    (self=, recursive=1, cb=0x55555584e498 <_sidebar_branch_children_reordered_callback_sidebar_branch_node_children_reordered_callback>, cb_target=0x55555dbe1140) at ../src/sidebar/Branch.vala:182
#18 0x00005555558507fe in sidebar_branch_node_reorder_childrenPython Exception <class 'ValueError'> Variable 'static_fundamental_type_nodes' not found.: 

    (self=, recursive=1, cb=0x55555584e498 <_sidebar_branch_children_reordered_callback_sidebar_branch_node_children_reordered_callback>, cb_target=0x55555dbe1140) at ../src/sidebar/Branch.vala:182
#19 0x000055555584e521 in sidebar_branch_reorder_all (self=0x55555dbe1140) at ../src/sidebar/Branch.vala:338
#20 0x00005555557e9bc7 in events_branch_set_sort_ascending (self=0x55555dbe1140, value=0) at ../src/events/Branch.vala:37
#21 0x00005555557e6660 in __lambda65_ (self=0x55555dbe1140, key=0x55555dbde450 "events-sort-ascending") at ../src/events/Branch.vala:68
#22 0x00005555557e668d in ___lambda65__g_settings_changed (_sender=0x55555dbe04d0, key=0x55555dbde450 "events-sort-ascending", self=0x55555dbe1140) at ../src/events/Branch.vala:66
#23 0x00007ffff7c5990f in g_cclosure_marshal_VOID__STRINGv () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#24 0x00007ffff7c56a56 in  () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#25 0x00007ffff7c75b48 in g_signal_emit_valist () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#26 0x00007ffff7c760f3 in g_signal_emit () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#27 0x00007ffff7d9ca20 in  () at /lib/x86_64-linux-gnu/libgio-2.0.so.0
#28 0x00007ffff7d26585 in  () at /lib/x86_64-linux-gnu/libgio-2.0.so.0
#29 0x00007ffff7c56a56 in  () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#30 0x00007ffff7c74df1 in g_signal_emit_valist () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#31 0x00007ffff7c760f3 in g_signal_emit () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#32 0x00007ffff7d9e07c in  () at /lib/x86_64-linux-gnu/libgio-2.0.so.0
#33 0x00007ffff7d97e1f in  () at /lib/x86_64-linux-gnu/libgio-2.0.so.0
#34 0x00007ffff7ed6315 in g_main_context_invoke_full () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#35 0x00007ffff7d97f68 in  () at /lib/x86_64-linux-gnu/libgio-2.0.so.0
#36 0x00007ffff7fb7141 in  () at /usr/lib/x86_64-linux-gnu/gio/modules/libdconfsettings.so
#37 0x00007ffff7fb8787 in  () at /usr/lib/x86_64-linux-gnu/gio/modules/libdconfsettings.so
#38 0x00007ffff7fb580f in  () at /usr/lib/x86_64-linux-gnu/gio/modules/libdconfsettings.so
#39 0x00007ffff7d98ba9 in  () at /lib/x86_64-linux-gnu/libgio-2.0.so.0
#40 0x00007ffff7d9d2a3 in  () at /lib/x86_64-linux-gnu/libgio-2.0.so.0
#41 0x00007ffff7d9f0b8 in g_settings_set_value () at /lib/x86_64-linux-gnu/libgio-2.0.so.0
#42 0x00005555557f968b in library_window_on_events_sort_changed (self=0x55555dbd9f40, action=0x55555eb78150, c=0x55555dbdac50) at ../src/library/LibraryWindow.vala:740
#43 0x00005555557f50cd in _library_window_on_events_sort_changed_gcallback (action=0x55555eb78150, current=0x55555dbdac50, self=0x55555dbd9f40) at ../src/library/LibraryWindow.vala:407
#44 0x00007ffff7c56802 in g_closure_invoke () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#45 0x00007ffff7c6a814 in  () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#46 0x00007ffff7c75bbe in g_signal_emit_valist () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#47 0x00007ffff7c760f3 in g_signal_emit () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#48 0x00007ffff7232c5f in  () at /lib/x86_64-linux-gnu/libgtk-3.so.0
#49 0x00007ffff7c56802 in g_closure_invoke () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#50 0x00007ffff7c6a962 in  () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#51 0x00007ffff7c75bbe in g_signal_emit_valist () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#52 0x00007ffff7c760f3 in g_signal_emit () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#53 0x00007ffff72168e5 in  () at /lib/x86_64-linux-gnu/libgtk-3.so.0
#54 0x00005555557fbb20 in library_window_load_configuration (self=0x55555dbd9f40) at ../src/library/LibraryWindow.vala:1032
#55 0x00005555557f2794 in library_window_constructPython Exception <class 'gdb.error'> No type named TypeNode.: 
 (object_type=, progress_monitor=0x555555667396 <_aggregate_progress_monitor_monitor_progress_monitor>, progress_monitor_target=0x555555d788d0)
    at ../src/library/LibraryWindow.vala:272
#56 0x00005555557f2ca6 in library_window_new (progress_monitor=0x555555667396 <_aggregate_progress_monitor_monitor_progress_monitor>, progress_monitor_target=0x555555d788d0)
    at ../src/library/LibraryWindow.vala:260
#57 0x000055555566838d in library_exec (mounts=0x555555ba5960, mounts_length1=0) at ../src/main.vala:157
#58 0x0000555555669874 in _vala_main (args=0x7fffffffdac8, args_length1=1) at ../src/main.vala:381
#59 0x0000555555669bdf in main (argc=1, argv=0x7fffffffdac8) at ../src/main.vala:286
asonix commented 3 years ago

For context, after commenting out this line: https://github.com/elementary/photos/blob/073f5a8351fe4eca5543622805fced24c4287ef5/src/events/Branch.vala#L37 I can launch photos in 6 seconds

vjr commented 3 years ago

@asonix would you be able to test my PR #651 to see if it makes a difference with your media collection?

vjr commented 3 years ago

This is where the massive slowdown appears to be occurring:

https://github.com/elementary/photos/blob/bc7feca8caa4c8fc076a759a2d36e26e93c75596/src/sidebar/Tree.vala#L682

vjr commented 3 years ago

I tried calling set_model (null) before and set_model (store) after the foreach loop to no avail.