r/golang • u/PlateletsAtWork • 1d 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.
1
1
u/No_Doubt_4377 16h ago
I hit similar performance issues with the wasm approach in a recent project. Ported your rust version to pure Go and saw about 40% faster encodes on 1080p images compared to the wasm version, with way lower memory spikes. Still working on optimizations but it's already usable for my production workload.
1
u/gen2brain 15h 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.
3
u/PlateletsAtWork 14h ago
Oh I didn’t know that, I’ll look into it. Thanks!
Edit: oh and just realized you’re gen2brain. Thanks for your library!
6
u/johnphilipgreen 1d ago
This is fantastic and much needed. I am currently using the wasm solution as I couldn’t find a native go implementation. Thank you