Skip to content

Browsing services discoveries blocks the UI thread

Opening to the "browse" menu often freezes the UI.

The problem is the conjunction of the following two factors:

  1. the SD are created synchronously from the main thread:
#1  0x00007ffff69ff3f4 in generic_start (func=0x7fffc9d51487 <Open>, forced=true, ap=0x7fffe283c4c0) at ../../src/modules/modules.c:275
#2  0x00007ffff69ff056 in vlc_module_load (log=0x602000000658, capability=0x7ffff6e5ee60 "services_discovery", name=0x602000247930 "udisks", strict=true, probe=0x7ffff69ff258 <generic_start>) at ../../src/modules/modules.c:243
#3  0x00007ffff69ff52a in module_need (obj=0x6080001cefa0, cap=0x7ffff6e5ee60 "services_discovery", name=0x602000247930 "udisks", strict=true) at ../../src/modules/modules.c:286
#4  0x00007ffff6ba979f in vlc_sd_Create (parent=0x606000043ac0, cfg=0x6020002455f0 "udisks", owner=0x7fffe283c6d0) at ../../src/input/services_discovery.c:118
#5  0x00007ffff69f709f in vlc_media_source_New (provider=0x606000043ac0, name=0x6020002455f0 "udisks") at ../../src/media_source/media_source.c:139
#6  0x00007ffff69f7e69 in vlc_media_source_provider_Add (provider=0x606000043ac0, name=0x6020002455f0 "udisks") at ../../src/media_source/media_source.c:255
#7  0x00007ffff69f7fef in vlc_media_source_provider_GetMediaSource (provider=0x606000043ac0, name=0x6020002455f0 "udisks") at ../../src/media_source/media_source.c:272
#8  0x00007fffea731202 in NetworkDeviceModel::initializeMediaSources() (this=0x61100057e580) at ../../modules/gui/qt/network/networkdevicemodel.cpp:287
#9  0x00007fffea72a178 in NetworkDeviceModel::setCtx(MainCtx*) (this=0x61100057e580, ctx=0x6110001033c0) at ../../modules/gui/qt/network/networkdevicemodel.cpp:88
  1. the SD creation (their Open callback) may perform blocking calls.

Here are some measurements (in µs):

diff
diff --git a/src/input/services_discovery.c b/src/input/services_discovery.c
index b872c5b900..c1270cb2f6 100644
--- a/src/input/services_discovery.c
+++ b/src/input/services_discovery.c
@@ -115,8 +115,10 @@ services_discovery_t *vlc_sd_Create(vlc_object_t *parent, const char *cfg,
     sd->description = NULL;
     sd->owner = *owner;
 
+    vlc_tick_t t = vlc_tick_now();
     sd->p_module = module_need(sd, "services_discovery",
                                sd->psz_name, true);
+    fprintf(stderr, "=== %s: %ld\n", sd->psz_name, vlc_tick_now() - t);
     if (sd->p_module == NULL)
     {
         msg_Err(sd, "no suitable services discovery module");
=== upnp: 51961
=== avahi: 11577
=== sap: 249
=== pulse: 7857
=== udisks: 32402
=== v4l: 5613
=== disc: 8730
=== mtp: 211
=== xcb_apps: 4660

Here, the total is ~123ms, so the UI is frozen for that amount of time, so it feels laggy.

Edited by Romain Vimont
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information