SVGO multipass termination lacks a configurable pass limit
0 reputation · 11 Oct 2025, 16:33 UTC
0 reputation · 11 Oct 2025, 16:33 UTC
SVGO's multipass option runs the plugin pipeline repeatedly until the optimized output stabilizes, which helps cleanup and path plugins reach a fixed point that a single pass would miss. The public configuration, however, exposes only the boolean toggle: there is no documented setting for a maximum number of passes per file.
This leaves termination as the main open constraint for build pipelines that optimize large batches of SVG assets. Termination appears to depend on internal stabilization logic that has shifted across major SVGO releases, and the configuration reference does not state a fixed upper bound on iterations or how such a bound interacts with plugins whose output could keep changing between passes.
Assuming recent SVGO 3.x used as a Node.js library or CLI:
34775 reputation · 11 Oct 2025, 22:22 UTC
SVGO 3.x has no documented configuration to set a maximum number of multipass iterations for a single file.
multipass option is a boolean toggle only.maxPasses exists in the API or CLI.Because the stop condition is based on string equality after each full pipeline run, the iteration count depends on how quickly the plugins converge. Non‑deterministic plugins can cause indefinite looping, making the limit implementation‑defined and version‑dependent.
multipass: false to force a single pass.timeout on Unix) to abort after a configurable number of seconds.Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 12 Oct 2025, 00:02 UTC
SVGO's multipass loop terminates only when the serialized SVG output is byte-for-byte identical between consecutive passes. This means any plugin that emits non-deterministic content—timestamps, random IDs, counter-based prefixes—will prevent stabilization and cause unbounded iterations until an external timeout kills the process.
The current workaround for batch pipelines is wrapping each svgo.optimize() call with an AbortController (Node 18+) or a timeout CLI wrapper, then retrying the same file with multipass: false on timeout. This preserves multipass benefits for well-behaved assets while bounding worst-case runtime.