From 249dc8530c0efc2766606a940c1c50b434b2f1cd Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Thu, 8 Nov 2018 18:34:23 -0500 Subject: [PATCH] draw: re-enable the image.Rectangle DstMask fast path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change reverts the remaining part of CL 9463, the image.Rectangle DstMask fast path, since Go 1.5 has been released. $ go test -bench=. -count=5 -timeout=1h > before.txt $ # apply change $ go test -bench=. -count=5 -timeout=1h > after.txt $ benchstat before.txt after.txt name old time/op new time/op delta SimpleScaleCopy-8 23.4µs ± 3% 21.8µs ± 4% -7.14% (p=0.016 n=5+5) SimpleTransformCopy-8 22.6µs ± 6% 21.4µs ± 1% -5.07% (p=0.008 n=5+5) SimpleTransformScale-8 904µs ± 0% 900µs ± 0% ~ (p=0.056 n=5+5) ScaleNNLargeDown-8 641µs ± 1% 643µs ± 1% ~ (p=0.548 n=5+5) ScaleABLargeDown-8 1.50ms ± 1% 1.50ms ± 1% ~ (p=0.413 n=5+4) ScaleBLLargeDown-8 192ms ± 5% 196ms ± 4% ~ (p=0.095 n=5+5) ScaleCRLargeDown-8 355ms ± 4% 350ms ± 2% ~ (p=0.690 n=5+5) ScaleNNDown-8 134µs ± 2% 126µs ± 1% -5.68% (p=0.008 n=5+5) ScaleABDown-8 261µs ± 3% 256µs ± 1% -1.92% (p=0.016 n=5+5) ScaleBLDown-8 2.42ms ± 3% 2.44ms ± 8% ~ (p=0.841 n=5+5) ScaleCRDown-8 4.36ms ± 1% 4.85ms ± 4% +11.22% (p=0.008 n=5+5) ScaleNNUp-8 6.27ms ± 2% 6.72ms ± 3% +7.20% (p=0.008 n=5+5) ScaleABUp-8 12.8ms ± 1% 13.8ms ± 2% +7.26% (p=0.008 n=5+5) ScaleBLUp-8 17.5ms ± 7% 17.4ms ± 2% ~ (p=1.000 n=5+5) ScaleCRUp-8 23.2ms ± 2% 23.1ms ± 4% ~ (p=0.690 n=5+5) ScaleNNSrcRGBA-8 419µs ± 1% 421µs ± 3% ~ (p=0.690 n=5+5) ScaleNNSrcUnif-8 3.35µs ± 3% 3.35µs ± 2% ~ (p=1.000 n=5+5) ScaleNNOverRGBA-8 470µs ± 1% 479µs ± 5% ~ (p=0.548 n=5+5) ScaleNNOverUnif-8 102µs ± 2% 102µs ± 1% ~ (p=0.222 n=5+5) TformNNSrcRGBA-8 215µs ± 1% 213µs ± 1% ~ (p=0.222 n=5+5) TformNNSrcUnif-8 84.2µs ± 1% 86.6µs ± 2% +2.82% (p=0.016 n=5+5) TformNNOverRGBA-8 351µs ± 5% 359µs ± 0% ~ (p=0.151 n=5+5) TformNNOverUnif-8 101µs ± 1% 104µs ± 1% +3.47% (p=0.008 n=5+5) ScaleABSrcGray-8 399µs ± 2% 400µs ± 2% ~ (p=0.690 n=5+5) ScaleABSrcNRGBA-8 795µs ± 1% 809µs ± 4% ~ (p=0.095 n=5+5) ScaleABSrcRGBA-8 807µs ± 1% 807µs ± 2% ~ (p=1.000 n=5+5) ScaleABSrcYCbCr-8 1.50ms ± 1% 1.48ms ± 0% -0.76% (p=0.032 n=5+5) ScaleABOverGray-8 396µs ± 0% 395µs ± 1% ~ (p=0.421 n=5+5) ScaleABOverNRGBA-8 886µs ± 1% 885µs ± 1% ~ (p=0.556 n=4+5) ScaleABOverRGBA-8 893µs ± 1% 895µs ± 1% ~ (p=0.310 n=5+5) ScaleABOverYCbCr-8 1.49ms ± 1% 1.49ms ± 1% ~ (p=0.548 n=5+5) TformABSrcGray-8 359µs ± 1% 364µs ± 3% ~ (p=0.421 n=5+5) TformABSrcNRGBA-8 618µs ± 1% 660µs ± 3% +6.81% (p=0.008 n=5+5) TformABSrcRGBA-8 614µs ± 1% 638µs ± 5% +3.94% (p=0.008 n=5+5) TformABSrcYCbCr-8 903µs ± 1% 913µs ± 2% ~ (p=0.056 n=5+5) TformABOverGray-8 362µs ± 3% 358µs ± 1% ~ (p=0.421 n=5+5) TformABOverNRGBA-8 691µs ± 1% 690µs ± 1% ~ (p=0.841 n=5+5) TformABOverRGBA-8 671µs ± 1% 673µs ± 1% ~ (p=0.690 n=5+5) TformABOverYCbCr-8 904µs ± 1% 906µs ± 0% ~ (p=0.190 n=5+4) ScaleCRSrcGray-8 9.24ms ± 1% 9.16ms ± 1% ~ (p=0.222 n=5+5) ScaleCRSrcNRGBA-8 21.9ms ± 2% 21.7ms ± 1% ~ (p=0.222 n=5+5) ScaleCRSrcRGBA-8 22.5ms ± 8% 21.8ms ± 1% ~ (p=1.000 n=5+5) ScaleCRSrcYCbCr-8 43.6ms ± 1% 43.9ms ± 1% ~ (p=0.222 n=5+5) ScaleCROverGray-8 9.24ms ± 0% 9.35ms ± 6% ~ (p=0.690 n=5+5) ScaleCROverNRGBA-8 21.9ms ± 1% 21.8ms ± 1% ~ (p=0.548 n=5+5) ScaleCROverRGBA-8 21.8ms ± 0% 22.0ms ± 1% +0.94% (p=0.008 n=5+5) ScaleCROverYCbCr-8 43.5ms ± 1% 44.1ms ± 1% +1.53% (p=0.008 n=5+5) TformCRSrcGray-8 3.16ms ± 4% 3.06ms ± 1% ~ (p=0.056 n=5+5) TformCRSrcNRGBA-8 4.21ms ± 1% 4.20ms ± 1% ~ (p=0.841 n=5+5) TformCRSrcRGBA-8 4.29ms ± 1% 4.29ms ± 1% ~ (p=0.841 n=5+5) TformCRSrcYCbCr-8 5.55ms ± 1% 5.58ms ± 0% +0.67% (p=0.032 n=5+4) TformCROverGray-8 3.08ms ± 1% 3.07ms ± 2% ~ (p=0.421 n=5+5) TformCROverNRGBA-8 4.40ms ± 1% 4.39ms ± 0% ~ (p=0.841 n=5+5) TformCROverRGBA-8 4.50ms ± 5% 4.44ms ± 0% ~ (p=0.730 n=5+4) TformCROverYCbCr-8 5.57ms ± 0% 5.61ms ± 1% ~ (p=0.095 n=5+5) Change-Id: I981861c28e103b68275a82e051d2999a8e714502 Reviewed-on: https://go-review.googlesource.com/c/148575 Reviewed-by: Brad Fitzpatrick --- draw/scale.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/draw/scale.go b/draw/scale.go index 11784d4..00121a1 100644 --- a/draw/scale.go +++ b/draw/scale.go @@ -408,11 +408,9 @@ func clipAffectedDestRect(adr image.Rectangle, dstMask image.Image, dstMaskP ima if dstMask == nil { return adr, nil } - // TODO: enable this fast path once Go 1.5 is released, where an - // image.Rectangle implements image.Image. - // if r, ok := dstMask.(image.Rectangle); ok { - // return adr.Intersect(r.Sub(dstMaskP)), nil - // } + if r, ok := dstMask.(image.Rectangle); ok { + return adr.Intersect(r.Sub(dstMaskP)), nil + } // TODO: clip to dstMask.Bounds() if the color model implies that out-of-bounds means 0 alpha? return adr, dstMask }