Reducing CPU usage
James Pearson
james at ifixit.com
Tue Dec 18 23:17:36 CET 2012
Excerpts from Simon Lyall's message of 2012-12-18 14:10:37 -0800:
> On Tue, 18 Dec 2012, James Pearson wrote:
> > Towards the end, you mention moving a rule from being of the form
> >
> > if ((a || b ) && c) {
> >
> > to
> >
> > if (a || b) {
> > if (c) {
> >
> > , where c is an expensive check and (a || b) rules out most pages, and seeing a
> > CPU usage decrease. This seems odd to me, since I'd expect short-circuiting to
> > cut out the check for c if (a || b) is false.
>
> In reality what I did was closer to changing:
>
> if ((a || b ) && c) { }
> if ((a || b ) && d) { }
> if ((a || b ) && e) { }
>
> to:
>
> if (a || b) {
> if (c) { }
> if (d) { }
> if (e) { }
> }
>
> where c,d & e were large regex functions. The test ( a || b ) was matched
> about 14% of the time.
Ok, that makes more sense. Thanks for the clarification.
More information about the varnish-misc
mailing list