Speed up slicing without changing the G-code of a fresh slice (#17335)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Warren GreenandClaude Opus 5.5 authored and GitHub committed 2026-11-21 10:59:12 -03:00
1 parent 5a1ffc6a63
commit 1174b39004
25 files changed
+1034 -155

No files matched your search

+17 -11
View File
@@ -2854,6 +2854,7 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu
// BBS
m_curr_print = print;
m_overhang_layers_cache.valid = false;
m_skirt_group_done.clear();
m_pending_start_gcode_position.reset();
m_exclusion_volume_travel_avoidance.init(print->config(), print->get_plate_origin());
@@ -10854,12 +10855,22 @@ bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftTyp
std::pair<float, float> z_range;
z_range.second = m_layer ? m_layer->print_z : 0.f;
z_range.first = std::max(0.f, z_range.second - protect_z);
std::vector<LayerPtrs> layers_of_objects;
std::vector<BoundingBox> boundingBox_for_objects;
VecOfPoints objects_instances_shift;
std::vector<size_t> idx_of_object_sorted = m_curr_print->layers_sorted_for_object(z_range.first, z_range.second, layers_of_objects, boundingBox_for_objects, objects_instances_shift);
std::vector<bool> is_layers_of_objects_sorted(layers_of_objects.size(), false);
OverhangLayersCache &cache = m_overhang_layers_cache;
if (!cache.valid || cache.z_min != z_range.first || cache.z_max != z_range.second) {
cache.layers_of_objects.clear();
cache.boundingBox_for_objects.clear();
cache.idx_of_object_sorted = m_curr_print->layers_sorted_for_object(z_range.first, z_range.second, cache.layers_of_objects,
cache.boundingBox_for_objects, cache.objects_instances_shift);
for (LayerPtrs &layers : cache.layers_of_objects)
std::sort(layers.begin(), layers.end(), [](auto left, auto right) { return left->loverhangs_bbox.area() > right->loverhangs_bbox.area();});
cache.z_min = z_range.first;
cache.z_max = z_range.second;
cache.valid = true;
}
const std::vector<LayerPtrs> &layers_of_objects = cache.layers_of_objects;
const std::vector<BoundingBox> &boundingBox_for_objects = cache.boundingBox_for_objects;
const VecOfPoints &objects_instances_shift = cache.objects_instances_shift;
const std::vector<size_t> &idx_of_object_sorted = cache.idx_of_object_sorted;
for (size_t idx : idx_of_object_sorted) {
for (const Point & instance_shift : objects_instances_shift[idx]) {
@@ -10877,11 +10888,6 @@ bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role, LiftTyp
if (intersection_pl(travel, temp).empty())
continue;
if (!is_layers_of_objects_sorted[idx]) {
std::sort(layers_of_objects[idx].begin(), layers_of_objects[idx].end(), [](auto left, auto right) { return left->loverhangs_bbox.area() > right->loverhangs_bbox.area();});
is_layers_of_objects_sorted[idx] = true;
}
for (const auto& layer : layers_of_objects[idx]) {
for (ExPolygon overhang : layer->loverhangs) {
overhang.translate(instance_shift);