Processing export files to PDF or SVG

I have a question for the community, some of whom I’m hoping are using Processing for use with plotters as I am. My question is about working with exported files, either PDF or SVG. When I create intricate line work, I’m using vertex or curveVertex and based on my resolution, any given line could be made up of tens to hundreds of little segments. When I export this to either format, it creates huge, unwieldy files that I basically can’t work with because I’ll have possibly thousands to tens-of-thousands layers that my computer just can’t process.

So my question is whether anyone has found a way to code in such a way that reduces this count upon export or post-processing techniques in either Illustrator or Inkscape that can join line segments to reduce layer count and generally make it more amenable to editing of any sort? In the former, is there some way to code the that makes exporting more compact, be it a complete line as layer or some other trick? And in the later, which I know is outside the purview of this community, but asking anyway, are there maybe add-on or plug-in or scripts that automate the process?

Open to any suggestions, advice on process, code solutions, anything really because I’m running into a wall of being able take designs from the screen to the page.

I use py5 for plotting work. Python allows me to leverage xml.etree.ElementTree, vpype, and a few other libraries to help manage and optimise things.