perf(daemon): skip the UI-thread datadir lock wait
Starting the daemon polls for an already-running node holding the datadir, sleeping up to three 100 ms intervals to let a shutting-down node clear out. When a start runs on the UI thread, that is up to 300 ms of blocking sleep on the render thread. - The lock-wait poll count is now a parameter. A start invoked on the UI thread passes 0, which does a single check and never sleeps; every other caller keeps the three-poll wait. The default is unchanged, so background starts behave exactly as before. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -505,7 +505,7 @@ static bool isPortInUse(int port)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool EmbeddedDaemon::start(const std::string& binary_path)
|
||||
bool EmbeddedDaemon::start(const std::string& binary_path, int lockWaitPolls)
|
||||
{
|
||||
std::lock_guard<std::mutex> life(lifecycle_mutex_);
|
||||
|
||||
@@ -564,11 +564,10 @@ bool EmbeddedDaemon::start(const std::string& binary_path)
|
||||
// skip_port_check_ / -datadir override) are exempt; they run their own datadir+port.
|
||||
{
|
||||
constexpr int kDatadirLockWaitPollMs = 100;
|
||||
constexpr int kDatadirLockWaitMaxPolls = 3; // ~300ms total, breaks early on exit
|
||||
bool stillRunning = false;
|
||||
if (!skip_port_check_ && override_datadir_.empty()) {
|
||||
stillRunning = isDaemonProcessRunning();
|
||||
for (int i = 0; stillRunning && i < kDatadirLockWaitMaxPolls; ++i) {
|
||||
for (int i = 0; stillRunning && i < lockWaitPolls; ++i) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(kDatadirLockWaitPollMs));
|
||||
stillRunning = isDaemonProcessRunning();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user