diff --git a/CLAUDE.md b/CLAUDE.md index 092dec1f6..9843091be 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -28,6 +28,9 @@ npm run tauri dev # full Tauri dev build with hot reload npm run start:http # Vite dev server backed by test-http-api (no Tauri runtime) ``` +Set `VITE_LOG_INVOKE_TIMINGS=true` to log each command's duration +(`[invoke] ms`) to the browser console. It is off by default. + ### Checks and linting (tsc, svelte-check, eslint, prettier) ```sh diff --git a/README.md b/README.md index 7cbfa1ca0..041809db7 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,14 @@ To start the app in development mode with hot reload: npm run dev ``` +To log how long every backend command takes, for performance work, set +`VITE_LOG_INVOKE_TIMINGS=true`. Each call then prints `[invoke] ms` +to the browser console (visible at debug level): + +``` +VITE_LOG_INVOKE_TIMINGS=true npm run dev +``` + ## Releasing Releases are driven by an interactive, phased script. Start one with: diff --git a/src/lib/invoke.ts b/src/lib/invoke.ts index bc0dffde4..8e6caa6c9 100644 --- a/src/lib/invoke.ts +++ b/src/lib/invoke.ts @@ -16,7 +16,7 @@ export async function invoke( args?: tauri.InvokeArgs, options?: tauri.InvokeOptions, ): Promise { - if (import.meta.env.DEV) { + if (import.meta.env.VITE_LOG_INVOKE_TIMINGS === "true") { const start = performance.now(); try { return await withTestBackend(tauri.invoke, cmd, args, options); diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 4078e7476..8433e7809 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -1,2 +1,7 @@ /// /// + +interface ImportMetaEnv { + // eslint-disable-next-line @typescript-eslint/naming-convention + readonly VITE_LOG_INVOKE_TIMINGS?: string; +}