]> Cypherpunks repositories - gostls13.git/commit
image/draw: improve performances if mask is *image.Alpha
authorOlivier Wulveryck <olivier.wulveryck@gmail.com>
Mon, 31 May 2021 06:03:57 +0000 (08:03 +0200)
committerNigel Tao <nigeltao@golang.org>
Mon, 25 Oct 2021 12:07:15 +0000 (12:07 +0000)
commitfcd2d9cd75e6307b5b72fed2201044e231bef40a
tree6cb35379911e0bcf19767525992909ec82b14c4f
parent7b554575e46d1df9b68f71e051c8133aaf953fb7
image/draw: improve performances if mask is *image.Alpha

The existing DrawMask method is generic and is therefore calling the At().RGBA() method for every pixel of the mask and the source.
Do a specific implementation when the mask is *image.Alpha (which is
common) and use use the PixOffset method to increase performances.

name                old time/op  new time/op  delta
RGBA2-12            1.60ms ± 0%  1.13ms ± 1%  -29.16%  (p=0.008 n=5+5)
GenericMaskOver-12   915µs ± 4%   926µs ± 1%     ~     (p=0.190 n=5+4)
RGBA64Over-12       1.53ms ± 3%  1.21ms ± 2%  -20.74%  (p=0.008 n=5+5)
GrayOver-12         1.36ms ± 2%  1.01ms ± 7%  -26.27%  (p=0.008 n=5+5)

Fixes: #46395
Change-Id: Iaeaa8cfcc6a3fe93eb19b361f3bf076e41cac5b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/323749
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Trust: Nigel Tao <nigeltao@golang.org>
Trust: Andrew Gerrand <adg@golang.org>
Run-TryBot: Nigel Tao <nigeltao@golang.org>
src/image/draw/bench_test.go
src/image/draw/draw.go
src/image/draw/draw_test.go