Generate WebP images for JPG / PNG files on-the-fly with Rust! BlueCocoa/webp_server_rs
Speaking of switching to WebP image, at the first glance, I just did it in a very naive approach.
And that looks really promising, the size of the webp server, according to its description, had greatly reduced from 43 MB to 15 MB, and it is a single binary instead of webp_server with node_modules.
I cloned that project and added a tiny feature. However, I just found that although it is absolutely easy to implement the tiny feature, there is a potential design issue with the `fasthttp` module. In order to get everything work, it took me about 4 hours to debug on it.
Finally, it turned out to be a pointer of an internal variable (
ctx.Request.uri, or so) was directly returned from
ctx.Path(), and if users invoke
ctx.Request.uri will be set to
filepath, which will also propagate to all variables that hold the shared value of
ctx.Path(). You may visit my previous blog post for details.
Well, in aforementioned blog post, I said that it would be better if it was written in Rust. Now, let's make it come true and push the WebP server even further.
As for size,
- webp_server(nodejs) with node_modules takes 43 MB
- webp-server(go) has reduced to 15 MB, and it's single binary
- webp-server(Rust) pushes that even further, only 3.6 MB on macOS and 6.4 MB on Linux
In terms of convenience, you can just download the binary file and run if you choose either webp-server(go) or webp-server(Rust). However, webp_server(nodejs) requires
pm2 to run.
Performance, to be honest, I haven't got time to run some benchmarks on them. But IMHO it (webp-server(Rust)) should be as fast as golang version.