perf: speed up G-code export by 7-26% via typed config apply (#16026)

This commit is contained in:
Kris Austin
2026-09-30 18:58:22 -03:00
committed by GitHub
parent ffbbd62355
commit 865e9963c3
4 changed files with 104 additions and 6 deletions
+70
View File
@@ -1289,3 +1289,73 @@ TEST_CASE("Static print configs compare, order and hash by their option values",
REQUIRE(c.optptr("gcode_flavor") == &c.gcode_flavor);
}
}
namespace {
// Keys whose values differ between two full configs, compared as text so enum names count too.
std::vector<std::string> differing_keys(const FullPrintConfig &a, const FullPrintConfig &b)
{
std::vector<std::string> keys;
for (const std::string &key : a.keys())
if (a.opt_serialize(key) != b.opt_serialize(key))
keys.push_back(key);
return keys;
}
// Applies source to one full config member by member and to another key by key, as apply() did before
// static configs could apply themselves.
template<class Source> void check_member_apply_matches_key_apply(const Source &source)
{
FullPrintConfig by_member;
FullPrintConfig by_key;
by_member.apply(source);
by_key.apply_only(source, source.keys());
CHECK(differing_keys(by_member, by_key).empty());
CHECK_FALSE(differing_keys(by_member, FullPrintConfig()).empty());
}
} // namespace
TEST_CASE("A static config applies itself onto a config of its type as a lookup by name would", "[Config]")
{
SECTION("region config")
{
PrintRegionConfig region;
region.sparse_infill_pattern.value = ipGyroid;
region.outer_wall_speed.values = {37.};
region.sparse_infill_density.value = 35.;
FullPrintConfig full;
REQUIRE(region.apply_to(full));
check_member_apply_matches_key_apply(region);
}
SECTION("object config")
{
PrintObjectConfig object;
object.seam_position.value = spRear;
object.wall_generator.value = PerimeterGeneratorType::Arachne;
object.support_speed.values = {33.};
object.enable_support.value = true;
FullPrintConfig full;
REQUIRE(object.apply_to(full));
check_member_apply_matches_key_apply(object);
}
SECTION("G-code config, whose enum lists carry their names through a keys map")
{
GCodeConfig gcode;
gcode.z_hop_types.values = {int(zhtSpiral)};
gcode.retraction_length.values = {1.5};
FullPrintConfig full;
REQUIRE(gcode.apply_to(full));
check_member_apply_matches_key_apply(gcode);
}
}
TEST_CASE("A static config applied onto a config of another type falls back to a lookup by name", "[Config]")
{
PrintRegionConfig region;
region.sparse_infill_pattern.value = ipGyroid;
DynamicPrintConfig dynamic;
REQUIRE_FALSE(region.apply_to(dynamic));
dynamic.apply(region);
CHECK(dynamic.opt_serialize("sparse_infill_pattern") == "gyroid");
}