Speed up slicing of finely detailed models (#16741)

# Description

Slicing finely detailed models such as HueForge reliefs is up to twice
as fast. Two steps that ran on a single core
dominated these slices. G-code export spent most of its time working out
which object each extrusion belongs to, and
internal bridge detection stalled for tens of seconds on layers printed
over fully dense infill. On the relief
"Mensch oder Gott 2", the slice goes from 108 s to 54 s on an M5 Max and
from 116 s to 65 s on Windows.

Over a lower layer printed at full density, bridge detection now settles
most layers with a cheaper check before it
falls back to the full computation. That check can disagree with the
full computation in one case, which is accepted:
a solid sliver thinner than about 16 µm that Clipper's own offset
simplification folds. There, internal bridges can
come out differently from main.

No change to slicing output on any project tested. G-code and object
masses are identical to main.

# Screenshots/Recordings/Graphs

<!--
> Please attach relevant screenshots to showcase the UI changes.
> Please attach images that can help explain the changes.
-->

## Tests

New unit tests compare the bridge-detection helper with the full
computation, and cover the box-only island lookup.
Main and this branch were compared on the projects below. They were also
compared on OrcaCube variants that set each
density option below 100%, plus a spiral vase, a crowded plate and a
two-part assembly. Every case slices to
byte-identical G-code, ignoring the timestamp line, and to identical
object and body masses. Slice times are for the
CLI, two runs each, on an M5 Max:

| Project | main | this PR |
|---|---:|---:|
| Mensch oder Gott 2 | 107.7 s, 108.8 s | 54.3 s, 54.4 s |
| Stranger Things 169×250 | 100.6 s, 100.6 s | 65.2 s, 66.0 s |
| RDR Front 229×256 | 12.6 s, 12.6 s | 8.6 s, 8.6 s |
| Lupo+AMS | 13.0 s, 13.1 s | 10.0 s, 10.0 s |
| Eagle 200×200 | 34.6 s, 34.0 s | 33.7 s, 34.0 s |

and on Windows with an Intel Core Ultra 7 270K Plus (Release build,
clang-cl), where the G-code is identical to main's
too:

| Project | main | this PR |
|---|---:|---:|
| Mensch oder Gott 2 | 121.2 s, 111.7 s | 68.2 s, 61.0 s |
| Stranger Things 169×250 | 100.7 s, 93.0 s | 59.7 s, 65.1 s |
| RDR Front 229×256 | 13.9 s, 13.4 s | 10.3 s, 10.1 s |
| Lupo+AMS | 19.9 s, 13.9 s | 20.9 s, 11.4 s |
| Eagle 200×200 | 38.9 s, 37.5 s | 38.1 s, 37.1 s |

Eagle uses about 15 s less CPU on both machines, but its export is bound
by G-code generation, so its slice time does
not change. Lupo's first run on Windows was slow with both builds. Peak
memory is the same within run-to-run spread,
except that it is about 0.1–0.2 GB higher on Stranger Things on the M5
Max and about 0.1 GB higher on Mensch oder Gott 2
on Windows.

<!--
> A guide for users on how to download the artifacts from this PR.
-->

[How to Download Pull Requests Artifacts for
Testing](https://www.orcaslicer.com/wiki/how_to_download_pr_artifacts)
This commit is contained in:
SoftFever authored and GitHub committed 2026-10-22 14:38:36 +08:00
commit db1824dd5d
8 files changed
+280 -21

No files matched your search

+10 -7
View File
@@ -2649,9 +2649,11 @@ static void set_mass_locator(GCodeProcessor &processor, const Print &print)
model_instances.begin());
}
bodies_total += int(count * object->instances().size());
// Without bodies only the instance matters, which any island box of an instance no other reaches proves. The
// islands of crowded instances are tested strictly anyway.
for (const Layer *layer : layers) {
o.print_zs.emplace_back(layer->print_z);
o.islands.emplace_back(layer->lslices, scaled<coord_t>(1.));
o.islands.emplace_back(layer->lslices, scaled<coord_t>(1.), o.bodies_count > 0);
}
}
if (objects.empty())
@@ -2711,12 +2713,13 @@ static void set_mass_locator(GCodeProcessor &processor, const Print &print)
return GCodeProcessor::MassLocation{ o.first_instance + int(hit.instance),
o.bodies_count == 0 ? -1 : o.first_body + int(hit.instance * o.bodies_count + o.bodies[hit.layer][hit.island]) };
};
// A point lies on the first layer at or above it, as spiral vase rises through each layer.
// A point lies on the first layer whose print_z is at least its height less the tolerance, as spiral vase rises
// through each layer. Both paths below pick it alike, as lower_bound does.
const double z = point.z() - z_tolerance;
// Extrusions mostly follow each other on one island.
if (last) {
const Object &o = objects[last->object];
if (point.z() <= o.print_zs[last->layer] + z_tolerance &&
(last->layer == 0 || point.z() > o.print_zs[last->layer - 1] + z_tolerance) &&
if (!(o.print_zs[last->layer] < z) && (last->layer == 0 || o.print_zs[last->layer - 1] < z) &&
o.islands[last->layer].holds(last->island, local(last->object, last->instance), o.crowded[last->instance]))
return location(*last);
}
@@ -2725,10 +2728,10 @@ static void set_mass_locator(GCodeProcessor &processor, const Print &print)
double distance = std::numeric_limits<double>::max();
for (size_t object = 0; object < objects.size(); ++object) {
const Object &o = objects[object];
const auto z = std::lower_bound(o.print_zs.begin(), o.print_zs.end(), point.z() - z_tolerance);
if (z == o.print_zs.end())
const auto above = std::lower_bound(o.print_zs.begin(), o.print_zs.end(), z);
if (above == o.print_zs.end())
continue;
const size_t layer = size_t(z - o.print_zs.begin());
const size_t layer = size_t(above - o.print_zs.begin());
for (size_t instance = 0; instance < o.object->instances().size(); ++instance) {
const auto [island, d] = o.islands[layer].find(local(object, instance), o.crowded[instance]);
if (island < 0)