That's cool. Have you tried to make GIF compression lossy?
The idea is that when looking for longest match in the dictionary you don't match colors exactly, but instead allow some difference. That can reduce file size by 20-30% (here's my take on it in C: https://github.com/pornel/giflossy/commit/5a9adbc0feb899a228...)
Another optimization is to set pixels that are similar between frames to transparent color. That sometimes massively improves quality, as you only generate palette for part of the image (so the palette is better) and several frames overlaid together may give more than 256 colors.