Closed path micro-optimization: substitute z for the most wasteful segment
A simple closed path(*) terminated with a single z (the logic gets hairier when you have multiple zs) such as
<path d="m 10 0 v 10 l -10 -10 z">
…can be rotated around until its z close-path segment (here used in place of a short h 10 segment) replaces the most space-consuming of the line segments (here l -10 -10):
<path d="m 0 0 h 10 v 10 z">
(*) the example is a synonym to <polygon points="0,10 10,10 0,0"> – but the optimization can be applied to any path with curves, arcs and other things in it, as long as there is at least a line segment in there too
looks interesting :) but I still can not catch how to automate it...
(*) yeah, I thought about path -> polygon (or polyline) conversion if only line segments are present.
While I might miss which part poses the problem, I think it might not be all that hard if you have an SVG DOM (which I assume you do?). @Phrogz' convertToAbsolute example shows how to iterate around a segment at a time.
Figuring out if it's worth doing the optimization on a given part should be easy (probably even regexpable, if you like; /^[^Z]*L[^Z]*Z\s*$/i matching the d attribute, perhaps).
Tweaking convertToAbsolute to convert the Z into the H, V or L command it amounts to to get back to the first M should be pretty straight-forward.
Only line segments (l and L) are candidates to replace the z, so narrowing down the list to test to those candidates (including the replaced Z) and what they would serialize to in minimal form should pinpoint which of them is the longest.
Save the index i of that segment, absolutize the path, rotate it (rotating back the first i segments to the tail of the path instead), replace the last segment with a z and re-relativize the path, and it should now have its minimal form.