]> granicus.if.org Git - handbrake/commitdiff
libhb: Reduce the number of threads NLMeans uses with many logical cores.
authorBradley Sepos <bradley@bradleysepos.com>
Wed, 16 Jan 2019 06:38:37 +0000 (01:38 -0500)
committerBradley Sepos <bradley@bradleysepos.com>
Sat, 19 Jan 2019 19:18:19 +0000 (14:18 -0500)
Too many threads increases CPU cache pressure, reducing performance.

libhb/nlmeans.c

index 4352fa87ffc79c6b4de669beb77c5e1eddd2ff77..38b2c61c2d7f5afa03e06359e3931801d30a28e9 100644 (file)
@@ -994,8 +994,20 @@ static int nlmeans_init(hb_filter_object_t *filter,
         exptable[NLMEANS_EXPSIZE-1] = 0;
     }
 
-    // Sanitize
-    if (pv->threads < 1) { pv->threads = hb_get_cpu_count(); }
+    // Threads
+    if (pv->threads < 1) {
+        pv->threads = hb_get_cpu_count();
+
+        // Reduce internal thread count where we have many logical cores
+        // Too many threads increases CPU cache pressure, reducing performance
+        if (pv->threads >= 32) {
+            pv->threads = pv->threads / 2;
+        }
+        else if (pv->threads >= 16) {
+            pv->threads = (pv->threads / 4) * 3;
+        }
+    }
+    hb_log("NLMeans using %i threads", pv->threads);
 
     pv->frame = calloc(pv->threads + pv->max_frames, sizeof(Frame));
     for (int ii = 0; ii < pv->threads + pv->max_frames; ii++)