1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:44:41 -07:00
go/src/image
Cezar Sa Espinola 93a18acf1e image/png: reduce memory allocs encoding images by reusing buffers
This change allows greatly reducing memory allocations with a slightly
performance improvement as well.

Instances of (*png).Encoder can have a optional BufferPool attached to
them. This allows reusing temporary buffers used when encoding a new
image. This buffers include instances to zlib.Writer and bufio.Writer.

Also, buffers for current and previous rows are saved in the encoder
instance and reused as long as their cap() is enough to fit the current
image row.

A new benchmark was added to demonstrate the performance improvement
when setting a BufferPool to an Encoder instance:

$ go test -bench BenchmarkEncodeGray -benchmem
BenchmarkEncodeGray-4                 	    1000	   2349584 ns/op	 130.75 MB/s	  852230 B/op	      32 allocs/op
BenchmarkEncodeGrayWithBufferPool-4   	    1000	   2241650 ns/op	 137.04 MB/s	     900 B/op	       3 allocs/op

Change-Id: I4488201ae53cb2ad010c68c1e0118ee12beae14e
Reviewed-on: https://go-review.googlesource.com/34150
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-12 05:40:47 +00:00
..
color image/color: tweak the YCbCr to RGBA conversion formula again. 2017-02-10 22:57:50 +00:00
draw image/draw: add FloydSteinberg Drawer example 2016-09-21 00:08:58 +00:00
gif image/gif: fix frame-inside-image bounds checking. 2017-02-10 03:31:09 +00:00
internal/imageutil image/color: tweak the YCbCr to RGBA conversion formula again. 2017-02-10 22:57:50 +00:00
jpeg image/jpeg: improve performance when encoding *image.YCbCr 2017-02-01 21:38:59 +00:00
png image/png: reduce memory allocs encoding images by reusing buffers 2017-02-12 05:40:47 +00:00
testdata image/jpeg: reconstruct progressive images even if incomplete. 2016-03-31 00:33:24 +00:00
decode_example_test.go
decode_test.go image/jpeg: reconstruct progressive images even if incomplete. 2016-03-31 00:33:24 +00:00
format.go
geom_test.go image: fix the overlap check in Rectangle.Intersect. 2017-02-10 05:05:59 +00:00
geom.go image: fix the overlap check in Rectangle.Intersect. 2017-02-10 05:05:59 +00:00
image_test.go
image.go
names.go
ycbcr_test.go
ycbcr.go