summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2022-06-09 13:46:42 +0300
committerAvi Halachmi (:avih) <avihpit@yahoo.com>2022-06-09 14:38:24 +0300
commit7ff4a27eb600dc01d20547880056c13d6cf3e9e7 (patch)
treecbedad8cc7559c07c9343d766c87d71d6aae72a7
parent3a521592865e15325ab4f83d823a285457a3d11a (diff)
downloadmpv-7ff4a27eb600dc01d20547880056c13d6cf3e9e7.tar.bz2
mpv-7ff4a27eb600dc01d20547880056c13d6cf3e9e7.tar.xz
sub: jsre filter: abort init early on empty filter list
TL;DR: previously a JavaScript VM was created + destroyed whenever a sub track was initialized, even if no jsre filter was set. Now a JS VM is created only if jsre filters were set. Sub filters are initialized once when a subtitle track is chosen, and then whenever the sub track changes or when some sub options change. Sub filters init is synchronous - playback is suspended till it ends. A filter can abort init early (get disabled) depending on conditions specific to each filter. The regex and jsre filters aborted early if the filter is disabled (default is enabled) or if the track is not ass (relativey rare, e.g. bitmap subs). The init then iterates over the filter strings, and if the result is empty (common - no filter was added, but also if all strings failed regex init) then it's also aborted during init. While this iteration step is cheap with filter regex, with jsre it requires instanciating the JS VM (mujs) in advance in order to parse the filter strings at the list, and the VM is then destroyed if the list ends up empty. This VM create+destroy is fast but measurable (0.2 - 0.7 ms, slowest measured on 2010 MacBook Air), but can be avoided altogether if we check that the filter list is not empty before we create the VM. So now we do just that.
-rw-r--r--sub/filter_jsre.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/sub/filter_jsre.c b/sub/filter_jsre.c
index af4fbbeba3..f956000d55 100644
--- a/sub/filter_jsre.c
+++ b/sub/filter_jsre.c
@@ -74,6 +74,9 @@ static bool jsre_init(struct sd_filter *ft)
if (!ft->opts->rf_enable)
return false;
+ if (!(ft->opts->jsre_items && ft->opts->jsre_items[0]))
+ return false;
+
struct priv *p = talloc_zero(ft, struct priv);
ft->priv = p;
@@ -84,7 +87,7 @@ static bool jsre_init(struct sd_filter *ft)
}
talloc_set_destructor(p, destruct_priv);
- for (int n = 0; ft->opts->jsre_items && ft->opts->jsre_items[n]; n++) {
+ for (int n = 0; ft->opts->jsre_items[n]; n++) {
char *item = ft->opts->jsre_items[n];
int err = p_regcomp(p->J, p->num_regexes, item, JS_REGEXP_I | JS_REGEXP_M);