scottmudge / OctoPrint-MeatPack

Easy, fast, effective, and automatic g-code compression!
https://github.com/scottmudge/OctoPrint-MeatPack
BSD 4-Clause "Original" or "Old" License
122 stars 6 forks source link

Optimization: Simplify decimal numbers #13

Open hans-olav opened 3 years ago

hans-olav commented 3 years ago

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 :-)

bubnikv commented 2 years ago

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.