From 3b1a5c0630bf513411b95e24d3bad0e78e34b6e9 Mon Sep 17 00:00:00 2001 From: raistlin7447 Date: Sat, 26 Sep 2026 07:24:57 -0500 Subject: [PATCH] libslic3r: copy the configs a vendor keeps while resolving A vendor keeps a copy of each config its other entries inherit, and the filament library keeps every one of them for the vendors that inherit from it. The copy was made in commit, one entry at a time on the calling thread while the workers waited, and the library alone makes 960 of them. Whether an entry's config is kept depends only on names known before any entry resolves, so resolve_vendor_preset makes the copy alongside the rest of its work and commit moves it in. --- src/libslic3r/PresetBundle.cpp | 15 +++++++++------ src/libslic3r/PresetBundle.hpp | 3 +++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index dfb6820dd6..4d71f38bc3 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -6656,6 +6656,7 @@ PresetBundle::PresetInstall PresetBundle::resolve_vendor_preset(const CachedPres const VendorProfile& current_vendor_profile = *install.vendor_profile; const std::string& preset_name = entry.name; const DynamicPrintConfig* default_config = nullptr; + const bool retain = install.is_from_lib || install.inherited.count(preset_name) != 0; PresetInstall out; out.filament_id = entry.filament_id; @@ -6723,6 +6724,8 @@ PresetBundle::PresetInstall PresetBundle::resolve_vendor_preset(const CachedPres " contains incorrect keys: " + incorrect_keys + ", which were removed"); if (entry.instantiation == "false" && "Template" != vendor_name) { out.config_only = true; + if (retain) + out.retained = std::move(out.config); return out; } if (out.config.has("alias")) @@ -6814,6 +6817,8 @@ PresetBundle::PresetInstall PresetBundle::resolve_vendor_preset(const CachedPres out.file_path = (boost::filesystem::path(data_dir()) / vendor_name / entry.sub_path).make_preferred().string(); if (m_preserve_vendor_source_paths) out.file_path = (boost::filesystem::path(path) / vendor_name / entry.sub_path).make_preferred().string(); + if (retain) + out.retained = out.config; return out; } @@ -6832,11 +6837,9 @@ std::string PresetBundle::commit_vendor_preset(const CachedPreset& entry, Preset if (! resolved.reason.empty()) return resolved.reason; - const bool retain_config = install.is_from_lib || install.inherited.count(preset_name) != 0; - if (resolved.config_only) { - if (retain_config) - install.config_maps.emplace(preset_name, std::move(resolved.config)); + if (resolved.retained) + install.config_maps.emplace(preset_name, std::move(*resolved.retained)); if ((presets_collection->type() == Preset::TYPE_FILAMENT) && (!resolved.filament_id.empty())) install.filament_id_maps.emplace(preset_name, resolved.filament_id); return std::string(); @@ -6890,8 +6893,8 @@ std::string PresetBundle::commit_vendor_preset(const CachedPreset& entry, Preset install.substitutions->push_back({ preset_name, presets_collection->type(), PresetConfigSubstitutions::Source::ConfigBundle, std::string(), std::move(substitutions) }); - if (retain_config) - install.config_maps.emplace(preset_name, loaded.config); + if (resolved.retained) + install.config_maps.emplace(preset_name, std::move(*resolved.retained)); ++install.count; //BBS: add config related logs BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ", got preset " << loaded.name << ", filament_id " << loaded.filament_id diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index d84361bb4b..1f73d04787 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -729,6 +729,9 @@ private: std::vector errors; // What a base states for the presets that include it, when it is retained. std::optional included; + // The config kept for the entries that inherit this one, or for other + // vendors when this is the filament library. + std::optional retained; // Not instantiated, so it contributes a config and no preset. bool config_only { false }; // Non-empty when the entry is rejected, and says why.