From d5b4d266c732817cd0584cef7f984754ac0bf011 Mon Sep 17 00:00:00 2001 From: Matthias Nott Date: Mon, 9 Feb 2026 22:19:39 +0100 Subject: [PATCH] fix: Eliminate redundant Z coordinates in ZAA gcode output extrude_to_xyz() unconditionally emitted Z on every extrusion move via emit_xyz(), even when Z hadn't changed. With ZAA enabled, this produced ~987K redundant Z coordinates (98.2% of all Z emissions), causing 10-20% file bloat. Now compares quantized Z values before and after, and only emits Z when it actually differs at export precision (0.001mm). Reduces ZAA gcode Z emissions from 1,038,468 to 50,022 while preserving all legitimate contouring Z changes. --- src/libslic3r/GCodeWriter.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index b208148c2b..b576eacdb2 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -911,6 +911,11 @@ std::string GCodeWriter::extrude_arc_to_xy(const Vec2d& point, const Vec2d& cent std::string GCodeWriter::extrude_to_xyz(const Vec3d &point, double dE, const std::string &comment, bool force_no_extrusion) { + // Check if Z actually changes (at export precision) before emitting it. + // ZAA sloped extrusions call this for every segment, but many consecutive + // segments share the same quantized Z — emitting it every time is redundant. + bool z_changed = (GCodeG1Formatter::quantize_xyzf(point(2)) != GCodeG1Formatter::quantize_xyzf(m_pos(2))); + m_pos = point; m_lifted = 0; if (!force_no_extrusion) @@ -920,7 +925,10 @@ std::string GCodeWriter::extrude_to_xyz(const Vec3d &point, double dE, const std Vec3d point_on_plate = { point(0) - m_x_offset, point(1) - m_y_offset, point(2) }; GCodeG1Formatter w; - w.emit_xyz(point_on_plate); + if (z_changed) + w.emit_xyz(point_on_plate); + else + w.emit_xy(Vec2d(point_on_plate.x(), point_on_plate.y())); if (!force_no_extrusion) w.emit_e(filament()->E()); //BBS