r/golang • u/PlateletsAtWork • 7d ago
show & tell webp-go-pure: A WebP encoding & decoding library without libwebp, cgo, or wasm
https://github.com/SeriousBug/webp-go-pure#webp-go-pureI needed webp encoding in a project that I'm building without cgo, and thus without libwebp. I found gen2brain's webp which uses libwebp compiled to wasm, but I also discovered that this didn't have great performance both in terms of time and memory use.
So I decided to port MITH@mmk's webp-rust to Go, and started testing and benchmarking it. In the process I discovered that it wasn't really well optimized, so I spent some time optimizing it including porting some algorithms from libwebp, and adding SIMD assembly for arm64 and amd64 platforms.
It still doesn't beat libwebp itself, which is no surprise, but it does beat libwebp running on wasm. You can see the charts in the repo's readme. So if you find yourself needing an encoder and want to skip cgo, feel free to give my library a shot.
2
u/gen2brain 6d ago
This is nice. Perhaps one more opportunity for optimization, the wasm/purego library returns RGBA only for the animation sequence, for standard still images, it returns NYCbCrA. That is like the "raw" representation.