[vlc-devel] [PATCH] modules: do not recurse into plugin directories
RĂ©mi Denis-Courmont
remi at remlab.net
Thu Oct 27 21:00:39 CEST 2016
This speeds up LibVLC initialization significantly.
(On my primary system, a reduction of about 60% in run time.)
---
src/modules/bank.c | 53 +++++++++++++++++----------------------------------
src/modules/cache.c | 22 ---------------------
src/modules/modules.h | 1 -
3 files changed, 17 insertions(+), 59 deletions(-)
diff --git a/src/modules/bank.c b/src/modules/bank.c
index 3b27acb..dde6517 100644
--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -159,7 +159,6 @@ typedef struct module_bank
size_t size;
vlc_plugin_t **plugins;
- vlc_plugin_t *cache;
} module_bank_t;
/**
@@ -168,33 +167,14 @@ typedef struct module_bank
static int AllocatePluginFile (module_bank_t *bank, const char *abspath,
const char *relpath, const struct stat *st)
{
- vlc_plugin_t *plugin = NULL;
-
- /* Check our plugins cache first then load plugin if needed */
- if (bank->mode == CACHE_USE)
- {
- plugin = vlc_cache_lookup(&bank->cache, relpath);
-
- if (plugin->mtime != (int64_t)st->st_mtime
- || plugin->size != (uint64_t)st->st_size)
- {
- msg_Err(bank->obj, "stale plugins cache: modified %s",
- plugin->abspath);
- vlc_plugin_destroy(plugin);
- plugin = NULL;
- }
- }
-
- if (plugin == NULL)
- {
- plugin = module_InitDynamic(bank->obj, abspath, true);
- plugin->path = xstrdup(relpath);
- plugin->mtime = st->st_mtime;
- plugin->size = st->st_size;
- }
+ vlc_plugin_t *plugin = module_InitDynamic(bank->obj, abspath, true);
if (plugin == NULL)
return -1;
+ plugin->path = xstrdup(relpath);
+ plugin->mtime = st->st_mtime;
+ plugin->size = st->st_size;
+
module_StoreBank(plugin);
if (bank->mode == CACHE_RESET) /* Add entry to to-be-saved cache */
@@ -301,23 +281,24 @@ static void AllocatePluginPath(vlc_object_t *obj, const char *path,
};
if (mode == CACHE_USE)
- bank.cache = vlc_cache_load(obj, path, &modules.caches);
+ {
+ vlc_plugin_t *cache = vlc_cache_load(obj, path, &modules.caches);
+
+ while (cache != NULL)
+ {
+ vlc_plugin_t *plugin = cache;
+ cache = plugin->next;
+ module_StoreBank(plugin);
+ }
+ return;
+ }
else
msg_Dbg(bank.obj, "ignoring plugins cache file");
msg_Dbg(obj, "recursively browsing `%s'", bank.base);
/* Don't go deeper than 5 subdirectories */
- AllocatePluginDir (&bank, 5, path, NULL);
-
- /* Discard unmatched cache entries */
- while (bank.cache != NULL)
- {
- vlc_plugin_t *plugin = bank.cache;
-
- bank.cache = plugin->next;
- vlc_plugin_destroy(plugin);
- }
+ AllocatePluginDir(&bank, 5, path, NULL);
if (mode == CACHE_RESET)
CacheSave(obj, path, bank.plugins, bank.size);
diff --git a/src/modules/cache.c b/src/modules/cache.c
index b6ad4e3..a1cdf8a 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -722,26 +722,4 @@ out:
free (filename);
free (tmpname);
}
-
-/**
- * Looks up a plugin file in a table of cached plugins.
- */
-vlc_plugin_t *vlc_cache_lookup(vlc_plugin_t **cache, const char *path)
-{
- vlc_plugin_t **pp = cache, *plugin;
-
- while ((plugin = *pp) != NULL)
- {
- if (plugin->path != NULL && !strcmp(plugin->path, path))
- {
- *pp = plugin->next;
- plugin->next = NULL;
- return plugin;
- }
-
- pp = &plugin->next;
- }
-
- return NULL;
-}
#endif /* HAVE_DYNAMIC_PLUGINS */
diff --git a/src/modules/modules.h b/src/modules/modules.h
index 3dc1971..a1ebd4d 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -128,7 +128,6 @@ void module_Unload (module_handle_t);
/* Plugins cache */
vlc_plugin_t *vlc_cache_load(vlc_object_t *, const char *, block_t **);
-vlc_plugin_t *vlc_cache_lookup(vlc_plugin_t **, const char *relpath);
void CacheSave(vlc_object_t *, const char *, vlc_plugin_t *const *, size_t);
--
2.10.1
More information about the vlc-devel
mailing list