# Even faster box blur

I replaced the generic convolution box blur with an optimized implementation.

The main optimization comes from not having to recompute the whole weighted sum for each pixel, which is possible thanks to the box blur having equal weights for all pixels. This dropped the phone from 29 seconds to 18 seconds on my PC.

Next, I checked the WebKit code to see if I was doing anything sub-optimally and realized that I could move the division around a bit to reduce the number of divisions and floating point operations in general. This dropped the phone further from 18 seconds to 16 seconds, resulting in a total speedup of almost 50%.

I also rsvg-bench–tested `bugs/634324-blur-negative-transform.svg`

with `-p 1 -r 100`

which dropped from 23.30 seconds to 2.82 seconds (!), as well as `svg1.1/filters-*.svg`

with `-p 1 -r 100`

which dropped from 74.50 seconds to 55.47 seconds.

I also made the benchmarks to use the Criterion crate which provides very nice analysis and works on stable, and added the box blur benchmarks (which I used throughout making these optimizations).

Here's a phone flamegraph after all these optimizations. The Gaussian blur columns dropped from 36.98% to 19.65% (and also the left "half" became considerably thinner compared to the right "half"):