From d6f57b30665f2c10be2e569eea08148385ad2965 Mon Sep 17 00:00:00 2001 From: denis svinarchuk Date: Fri, 17 Jul 2026 02:08:53 +0100 Subject: [PATCH] perf: enable inter-layer forecast in single-nozzle flush ordering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable use_forcast in reorder_filaments_for_minimum_flush_volume_base to match the multi-extruder path behavior (line 1227). The forecast solver (solve_extruder_order_with_forcast) considers the next layer's filament set when choosing ordering for the current layer, minimizing inter-layer transition flush cost. Previously disabled (hardcoded false) in the single-nozzle/base path, causing suboptimal inter-layer transitions. The multi-extruder path already had this enabled. Measured on 5cubes (5 filaments, 35 layers, H2C): - Print time: -12 min (-10%) - Waste filament: -5g (-28%) - WT extrusion: -44% Limited to ≤5 filaments per nozzle per layer (O(N!×M!) complexity). --- src/libslic3r/GCode/ToolOrderUtils.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCode/ToolOrderUtils.cpp b/src/libslic3r/GCode/ToolOrderUtils.cpp index c8b8ac3fdc..1cf4dae1dd 100644 --- a/src/libslic3r/GCode/ToolOrderUtils.cpp +++ b/src/libslic3r/GCode/ToolOrderUtils.cpp @@ -1091,7 +1091,15 @@ namespace Slic3r if (layer + 1 < layer_filaments.size()) next_lf = layer_filaments[layer + 1]; std::vector filament_used_next_layer = collect_filaments_in_groups(filament_sets, next_lf); - bool use_forcast = false; + // Enable inter-layer forecast: when choosing filament ordering for current layer, + // also consider next layer's filament set to minimize inter-layer transition flush. + // solve_extruder_order_with_forcast() tries all permutations of curr+next layer + // and picks the ordering that minimizes total flush across both layers. + // This avoids expensive inter-layer transitions (e.g. ending layer with F2 when + // next layer starts with F3, costing flush[F2→F3], instead of ending with F3 + // which gives flush[F3→F3]=0). Limited to ≤5 filaments due to O(N!×M!) complexity. + // Matches the multi-extruder path behavior (ToolOrderUtils.cpp:1227). + bool use_forcast = (filament_used.size() <= max_n_with_forcast && filament_used_next_layer.size() <= max_n_with_forcast); float tmp_cost = 0; std::vector sequence; uint128_t hash_key = filament_list_to_hash_key(filament_used, filament_used_next_layer, curr_filament_id, use_forcast);