OctoPrint-MeatPack icon indicating copy to clipboard operation
OctoPrint-MeatPack copied to clipboard

Optimization: Simplify decimal numbers

Open hans-olav opened this issue 3 years ago • 1 comments

I was looking into ways of packing better and think I've found two that would require no firmware changes.

  1. 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.
  2. 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 :-)

hans-olav avatar Feb 06 '21 04:02 hans-olav

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.

bubnikv avatar Apr 28 '22 09:04 bubnikv