From 9c046c7c2433bf8c30c0a1da4cf509810e151b36 Mon Sep 17 00:00:00 2001 From: Ian Chua Date: Fri, 24 Apr 2026 13:54:09 +0800 Subject: [PATCH] Dedupe json traversal (#13334) * WIP: benchmarking caching vs multi-thread parsing json * stick to just caching, other functions does not seem to have any duplicate traversals * Remove benchmarking code * cleanup leftover code and clear cache when loading is done --------- Co-authored-by: SoftFever --- src/slic3r/GUI/WebGuideDialog.cpp | 32 +++++++++++++++++++++++++++---- src/slic3r/GUI/WebGuideDialog.hpp | 10 ++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/WebGuideDialog.cpp b/src/slic3r/GUI/WebGuideDialog.cpp index 2933dd7bc9..05bc2ab287 100644 --- a/src/slic3r/GUI/WebGuideDialog.cpp +++ b/src/slic3r/GUI/WebGuideDialog.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "MainFrame.hpp" #include @@ -985,6 +986,17 @@ int GuideFrame::GetFilamentInfo( std::string VendorDirectory, json & pFilaList, //GetStardardFilePath(filepath); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " GetFilamentInfo:VendorDirectory - " << VendorDirectory << ", Filepath - "<second.vendor; + } + if (sType.empty()) { + sType = cache_it->second.type; + } + return cache_it->second.status; + } + try { std::string contents; LoadFile(filepath, contents); @@ -1014,6 +1026,7 @@ int GuideFrame::GetFilamentInfo( std::string VendorDirectory, json & pFilaList, if (!pFilaList.contains(FName)) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "pFilaList - Not Contains inherits filaments: " << FName; + filament_info_cache[filepath] = CachedFilamentInfo{-1, sVendor, sType}; return -1; } @@ -1025,28 +1038,36 @@ int GuideFrame::GetFilamentInfo( std::string VendorDirectory, json & pFilaList, inherits_path = (boost::filesystem::path(m_OrcaFilaLibPath) / boost::filesystem::path(FPath)).make_preferred(); //boost::filesystem::path nf(strNewFile.c_str()); - if (boost::filesystem::exists(inherits_path)) - return GetFilamentInfo(VendorDirectory,pFilaList, inherits_path.string(), sVendor, sType); - else { + if (boost::filesystem::exists(inherits_path)) { + const int ret = GetFilamentInfo(VendorDirectory,pFilaList, inherits_path.string(), sVendor, sType); + filament_info_cache[filepath] = CachedFilamentInfo{ret, sVendor, sType}; + return ret; + } else { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " inherits File Not Exist: " << inherits_path; + filament_info_cache[filepath] = CachedFilamentInfo{-1, sVendor, sType}; return -1; } } else { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << filepath << " - Not Contains inherits"; if (sType == "") { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "sType is Empty"; + filament_info_cache[filepath] = CachedFilamentInfo{-1, sVendor, sType}; return -1; } else sVendor = "Generic"; + filament_info_cache[filepath] = CachedFilamentInfo{0, sVendor, sType}; return 0; } } - else + else { + filament_info_cache[filepath] = CachedFilamentInfo{0, sVendor, sType}; return 0; + } } catch(nlohmann::detail::parse_error &err) { BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": parse "< + #include namespace Slic3r { namespace GUI { @@ -135,6 +137,14 @@ private: wxString m_bbl_user_agent; std::string m_editing_filament_id; + + struct CachedFilamentInfo + { + int status{-1}; + std::string vendor; + std::string type; + }; + std::unordered_map filament_info_cache; }; }} // namespace Slic3r::GUI