perf(lite): cache walletExists() to stop per-frame FFI
While no lite wallet is open the startup auto-open check called walletExists() every frame. That call crosses into the backend and touches the filesystem (and prints), so it ran a disk stat on every frame the app idled at the first-run prompt. - walletExists() now caches its result for about two seconds on the main thread, and the cache is invalidated whenever an open or lifecycle result is consumed, since the wallet file may have changed. - The auto-open condition is reordered so the cheap timer checks gate the call, and the click-time overwrite decision uses a new walletExistsFresh() that bypasses the cache. Tests: the cache returns the first queried value within the TTL and the fresh read re-queries the backend and refreshes the cache. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+3
-3
@@ -952,8 +952,8 @@ void App::update()
|
||||
const double nowSecs = ImGui::GetTime();
|
||||
const double retryInterval = lite_wallet_->lastOpenWasWarmup() ? 4.0 : 20.0;
|
||||
if (!lite_wallet_->walletOpen() && !lite_wallet_->openInProgress() &&
|
||||
lite_wallet_->walletExists() &&
|
||||
(!lite_autoopen_done_ || nowSecs - lite_open_last_attempt_ > retryInterval)) {
|
||||
(!lite_autoopen_done_ || nowSecs - lite_open_last_attempt_ > retryInterval) &&
|
||||
lite_wallet_->walletExists()) {
|
||||
lite_autoopen_done_ = true;
|
||||
lite_open_last_attempt_ = nowSecs;
|
||||
lite_wallet_->beginOpenExisting();
|
||||
@@ -3718,7 +3718,7 @@ void App::renderLiteFirstRunPrompt()
|
||||
wallet::LiteWalletRestoreRequest req;
|
||||
req.seedPhrase = seedTrim; // normalized: NBSP-glued pastes restore correctly
|
||||
req.birthday = static_cast<unsigned long long>(std::max(0, restoreBirthday));
|
||||
req.overwrite = lite_wallet_->walletExists(); // replace any existing wallet file
|
||||
req.overwrite = lite_wallet_->walletExistsFresh(); // replace any existing wallet file
|
||||
if (lite_wallet_->beginRestoreWalletAsync(std::move(req))) {
|
||||
restoreErr.clear();
|
||||
restoring = true;
|
||||
|
||||
Reference in New Issue
Block a user