Path: csiph.com!goblin2!goblin3!goblin.stu.neva.ru!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Kaz Kylheku <336-986-7787@kylheku.com> Newsgroups: comp.compilers Subject: Re: How to Optimize a Black Box Date: Fri, 24 Mar 2017 20:51:20 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 34 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <17-03-011@comp.compilers> References: <17-03-010@comp.compilers> Injection-Info: miucha.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="39077"; mail-complaints-to="abuse@iecc.com" Keywords: code, optimize Posted-Date: 27 Mar 2017 22:36:58 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1832 On 2017-03-24, Seima Rao wrote: > My question is how do we start at all in optimizing a black box ? If the black box behaves as a function (a pure mapping from some inputs to some outputs) and that function appears to be expensive, one way to begin is to look at caching: don't call the black box more than once on the same combination of inputs. That is, obtain the benefits of the black box being called M times, with N < M actual calls to the blackbox, and M - N being canned answers from the cache. If you can determine some properties of the blackbox without actually cracking it open, you can exploit them. It could be that, say, outside of some range of the parameter space, the function has some trivial result that can be short-circuited; yet the blackbox wastes cycles on it. A wrapper around it could take a shortcut, bypassing the blackbox. Like say we have a black-box which calculates the area under the normal distribution density function, between zero and some x. Suppose the black box is badly implemented and does lots of expensive calculations for large magnitudes of x, where the answer just comes out to be the obvious 0.5 or nearly so. (The "long tail" that outside of x contributes next to nothing to the area). We can just put in some logic around it like (fabs(x)) >= THRESHOLD) ? 0.5 : expensive_blackbox(x);. In this same vein, we could use a black box side-by-side with a crude approximation of the black-box. Say we have a black-box which gives an academically answer for every domain value of some function. But suppose that in our engineering or scientific application, most of the time, a "rule of thumb" approximation is completely satisfactory. We can evaluate the parameters to determine whether the simple, cheap approximation applies, or whether the blackbox needs to be invoked because the conditions are such that its superior model is critically relevant.