I remember trying (and giving up after like an hour waiting for it to complete) some Google thingy a few years back to optimize JPEGs. Both then and while looking at this I realize that the best solution is to use a newer image format.

Guetzli. Looks like development has stalled? Perhaps for just that reason.

https://github.com/google/guetzli