From: Bradley Sepos Date: Wed, 16 Jan 2019 06:38:37 +0000 (-0500) Subject: libhb: Reduce the number of threads NLMeans uses with many logical cores. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a7e9979c4af79b97cbc57a77ff96223a24731d0b;p=handbrake libhb: Reduce the number of threads NLMeans uses with many logical cores. Too many threads increases CPU cache pressure, reducing performance. --- diff --git a/libhb/nlmeans.c b/libhb/nlmeans.c index 4352fa87f..38b2c61c2 100644 --- a/libhb/nlmeans.c +++ b/libhb/nlmeans.c @@ -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++)