OctoPrint-MeatPack
OctoPrint-MeatPack copied to clipboard
Optimization: Simplify decimal numbers
I was looking into ways of packing better and think I've found two that would require no firmware changes.
-
Remove the leading 0 in decimal numbers less than 1. For example 0.123 => .123.
strtod
still parses this fine so no firmware changes should be required (have not tested this). In a sample 35MB .gcode file I tried, it saved about 2% and brought output size ratio from 49.6% (MeatPack with whitespace omit) to 47.7%, because the extruder step is almost always less than 1, so it can remove a character from most G1 lines. - Remove trailing 0s in decimal numbers. Remove decimals entirely if all 0s. For example: 0.120 => 0.12, 1.00 => 1 Less common, but it brought the output size down to 46.8%
So overall 2.8% additional packing with (in theory) no firmware changes. Not bad?
If you think this is worth pursuing I could send you a PR. Or feel free to take the suggestions and implement :-)
Remove the leading 0 in decimal numbers less than 1. For example 0.123 => .123.
PrusaSlicer does that by default (actually always) since 2.4.0.
Remove trailing 0s in decimal numbers. Remove decimals entirely if all 0s. For example: 0.120 => 0.12, 1.00 => 1
PrusaSlicer does that as well.