kolesa-team / go-webp

Simple and fast webp library for golang
MIT License
225 stars 36 forks source link

Add ImageFactory and Buffer to Options #29

Open tgrigsby-sc opened 1 year ago

tgrigsby-sc commented 1 year ago

Added an ImagePool and a Buffer as encoder options for improved encoding efficiency:

BenchmarkDecodePooled
BenchmarkDecodePooled-10          355448          3650 ns/op         581 B/op          6 allocs/op
BenchmarkDecodeUnPooled
BenchmarkDecodeUnPooled-10         99817         11573 ns/op       66210 B/op          8 allocs/op

The ImagePool will be used in the decode process to provide an image of the right dimensions if one already exists, which, once you're done with image, can be put back into the pool. Similarly, passing in the correct size of buffer will prevent multiple mem reallocs while writing.

See the benchmark test for details about usage.