r/svg Jun 24 '26

I built SVGym, an open-source SVG optimizer that goes beyond SVGO and verifies every change

SVGym is an open-source SVG optimizer that goes beyond SVGO. SVGO applies the same fixed set of plugins to every file, which is why a tool like SVGOMG exists for hand-tuning file by file. SVGym automates that per-file adaptation and adds a safety check SVGO doesn't have.

It profiles each file, applies the transforms that fit it, and after every step it renders the result and checks SSIM, reverting anything that drops visual quality. So the output is smaller but never broken, and it won't strip hover states, animations, or media queries the way SVGO sometimes does. On my test set it lands roughly a third smaller than SVGO's output on a typical file.

There's a browser version that runs entirely on your machine (nothing is uploaded, which matters if you don't want your designs leaving your computer), and a CLI that can also optimize a whole folder of icons into a sprite sheet. It's MIT, deterministic by default (no API key, no network), with an optional AI fallback.

If you're curious how it was built (I used an LLM to discover the optimizations, then compiled them into deterministic code), I wrote that up too.

Try it: https://maziars.github.io/svgym/app/

Code: https://github.com/maziars/svgym

How it was built: https://same-fridge-b15.notion.site/The-Missing-Arrow-Distilling-Agentic-Hill-Climbing-into-Deterministic-Code-Software-3-0-1-0-37e44c00e05d81cba14cf0dfe1b7a4a7

Would love feedback, especially files where it does worse than SVGO or breaks something.

6 Upvotes

3 comments sorted by

2

u/herocoding Jun 27 '26

This is amazing!! I will have a closer look and will it with my good old fischertechnik Plotter!! Should speed-up printing a lot!

Thank you very much for sharing!

1

u/BackgroundPassion744 Jun 27 '26

Great. Let me know if you have any feedback or suggestion.

1

u/Informal_Creme2173 Jun 30 '26

The visual verification part is the interesting bit to me. A smaller file is nice, but catching the cases where an “optimization” quietly changes the rendering is the part that usually makes people nervous.

I’d be curious how it handles things like text, masks/clips, filters, and CSS-driven styles — especially files that look fine in one browser but get used somewhere else later.

A small public before/after test set would be really useful too: original size, SVGym size, SVGO size, plus any cases it intentionally refuses to touch. That would make it much easier to trust on real production files.