From ecb878315c2a65a1d8d71d8953e5dd699d1650e8 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Thu, 14 May 2026 19:35:34 +0800 Subject: [PATCH] chore: add startup timing diagnostics for #270 Add [STARTUP] timing logs to Rust setup (plugin registration, storage open, migration) and Vue frontend (onMounted, initFromStorage, initFromDisk) to help diagnose slow startup reported in #270. --- src-tauri/src/lib.rs | 13 ++++++++++++- src/App.vue | 11 ++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d8c45c82f..cef320a88 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -12,6 +12,8 @@ use tauri::{Manager, RunEvent}; pub fn run() { rustls::crypto::aws_lc_rs::default_provider().install_default().expect("Failed to install rustls crypto provider"); + let startup_begin = Instant::now(); + tauri::Builder::default() .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_fs::init()) @@ -19,7 +21,10 @@ pub fn run() { .plugin(tauri_plugin_updater::Builder::new().build()) .plugin(tauri_plugin_process::init()) .plugin(tauri_plugin_window_state::Builder::default().build()) - .setup(|app| { + .setup(move |app| { + let setup_start = Instant::now(); + eprintln!("[STARTUP] plugins registered in {:?}", startup_begin.elapsed()); + if cfg!(debug_assertions) { app.handle().plugin(tauri_plugin_log::Builder::default().level(log::LevelFilter::Info).build())?; } @@ -29,17 +34,23 @@ pub fn run() { std::fs::create_dir_all(&data_dir).expect("Failed to create data dir"); let db_path = data_dir.join("dbx.db"); + let t = Instant::now(); let storage = tauri::async_runtime::block_on(async { let s = Storage::open(&db_path).await.expect("Failed to open storage"); + eprintln!("[STARTUP] Storage::open in {:?}", t.elapsed()); + let t2 = Instant::now(); s.migrate_from_json(&data_dir).await.expect("Failed to migrate JSON data"); + eprintln!("[STARTUP] migrate_from_json in {:?}", t2.elapsed()); s }); + eprintln!("[STARTUP] storage ready in {:?}", t.elapsed()); let state = Arc::new(AppState::new_with_plugin_dir(storage, data_dir.join("plugins"))); app.manage(state.clone()); let app_handle = app.handle().clone(); commands::mcp_bridge::start(app_handle, state); + eprintln!("[STARTUP] setup complete in {:?} (total {:?})", setup_start.elapsed(), startup_begin.elapsed()); #[cfg(not(target_os = "macos"))] { diff --git a/src/App.vue b/src/App.vue index f0bb770a8..e2d4d04ef 100644 --- a/src/App.vue +++ b/src/App.vue @@ -466,10 +466,16 @@ function onLoginSuccess() { } function initApp() { + const t0 = performance.now(); + console.log("[STARTUP] initApp begin"); savedSqlStore .initFromStorage() - .then(() => connectionStore.initFromDisk()) .then(() => { + console.log(`[STARTUP] savedSqlStore.initFromStorage: ${(performance.now() - t0).toFixed(0)}ms`); + return connectionStore.initFromDisk(); + }) + .then(() => { + console.log(`[STARTUP] connectionStore.initFromDisk: ${(performance.now() - t0).toFixed(0)}ms`); reconnectRestoredTabs(); }) .catch((e: any) => { @@ -501,6 +507,8 @@ function handleContextMenu(e: MouseEvent) { } onMounted(async () => { + console.log("[STARTUP] onMounted begin"); + const mountStart = performance.now(); applyTheme(); window.addEventListener("keydown", handleKeydown, true); if (isDesktop) { @@ -541,6 +549,7 @@ onMounted(async () => { }) .catch(() => {}); setupTauriListeners(); + console.log(`[STARTUP] onMounted sync done: ${(performance.now() - mountStart).toFixed(0)}ms`); }); onUnmounted(() => {