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:
2026-10-13 17:42:30 -05:00
co-authored by Claude Opus 4.8
parent 29c1674094
commit d601f786e2
4 changed files with 45 additions and 4 deletions
+17
View File
@@ -18146,6 +18146,22 @@ void testTransactionCsv() {
} // namespace
void testLiteWalletExistsCache()
{
using namespace dragonx::wallet;
const auto liteCaps = makeWalletCapabilities(WalletBuildKind::Lite, /*embeddedDaemon*/ false, /*liteBackendLinked*/ true);
const LiteConnectionSettings conn = defaultLiteConnectionSettings();
dragonx::test::resetLiteFakeCounters();
dragonx::test::g_liteFakeWalletExists = true;
LiteWalletController controller(liteCaps, conn, LiteClientBridge::fromApi(dragonx::test::makeFakeLiteApi()));
EXPECT_TRUE(controller.walletExists()); // queries backend, caches true
dragonx::test::g_liteFakeWalletExists = false;
EXPECT_TRUE(controller.walletExists()); // still cached (TTL not elapsed)
EXPECT_FALSE(controller.walletExistsFresh()); // uncached read, refreshes the cache
EXPECT_FALSE(controller.walletExists()); // cache now false
dragonx::test::g_liteFakeWalletExists = true; // restore default for later tests
}
int main()
{
testConnectionConfig();
@@ -18339,6 +18355,7 @@ int main()
testLiteClientBridgeUsesRuntimeOwnedStringCleanup();
testLiteBackendInjectableFakeBridge();
testLiteWalletControllerLifecycle();
testLiteWalletExistsCache();
testLiteWalletControllerOpenFailover();
testLiteWalletControllerAsyncLifecycleFailover();
testLiteWalletControllerConsoleCommand();