Skip to content

Commit dbd7c0b

Browse files
committed
FIX: debounce app_config->save() in wxEVT_IDLE handler (F-015)
The idle handler at GUI_App.cpp fired app_config->save() on every idle event whenever the config was dirty. On Windows with a busy idle loop this could produce dozens of synchronous disk writes per second. Add a 5-second debounce using std::chrono::steady_clock so the flush happens at most once every 5 s. Flush any remaining dirty state unconditionally in OnExit() so no settings are lost on clean exit. Ref: #10289
1 parent 4bf3e98 commit dbd7c0b

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/slic3r/GUI/GUI_App.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <iterator>
2222
#include <exception>
2323
#include <cstdlib>
24+
#include <chrono>
2425
#include <regex>
2526
#include <thread>
2627
#include <string_view>
@@ -2774,6 +2775,10 @@ int GUI_App::OnExit()
27742775
m_agent = nullptr;
27752776
}
27762777

2778+
// Flush any config changes that were deferred by the idle-handler debounce.
2779+
if (app_config && app_config->dirty())
2780+
app_config->save();
2781+
27772782
return wxApp::OnExit();
27782783
}
27792784

@@ -3314,8 +3319,16 @@ bool GUI_App::on_init_inner()
33143319
if (! plater_)
33153320
return;
33163321

3317-
if (app_config->dirty())
3318-
app_config->save();
3322+
if (app_config->dirty()) {
3323+
// Debounce: avoid synchronous disk writes on every idle event.
3324+
// Save at most once per 5 seconds; OnExit() flushes any remaining dirty state.
3325+
static auto s_last_config_save = std::chrono::steady_clock::time_point{};
3326+
const auto now = std::chrono::steady_clock::now();
3327+
if (now - s_last_config_save >= std::chrono::seconds(5)) {
3328+
app_config->save();
3329+
s_last_config_save = now;
3330+
}
3331+
}
33193332

33203333
// BBS
33213334
//this->obj_manipul()->update_if_dirty();

0 commit comments

Comments
 (0)