Open source personal finance application
perf(app): add cold-start instrumentation for cache prime and trns transform
Ilya Komichev57bca39cb930
diff --git a/app/app/components/app/useInitApp.ts b/app/app/components/app/useInitApp.tsindex 48303fd8..8cbbc38b 100644--- a/app/app/components/app/useInitApp.ts+++ b/app/app/components/app/useInitApp.ts@@ -109,14 +109,19 @@ export function useInitApp() {// Instant first paint: seed the stores from the last session's per-user snapshot while// PowerSync's db.init + first query scan are still running. The watches then reconcile to truth.async function primeStoresFromCache() {+ // Cold-start instrumentation: blob-cache read+prime time vs the SQLite watch path+ // (`ps:watch:*` measures) - feeds the blob-cache architecture decision.+ performance.mark('cache:prime:start')const snap = await readStoreCache()- if (!snap)- return- trnsStore.primeFromCache((snap.trns as Trns) ?? null)- categoriesStore.primeFromCache((snap.categories as Categories) ?? null)- walletsStore.primeFromCache((snap.wallets as Wallets) ?? null)- userStore.primeFromCache((snap.user as UserSettingsCache) ?? null)- currenciesStore.primeFromCache((snap.rates as Rates) ?? null)+ if (snap) {+ trnsStore.primeFromCache((snap.trns as Trns) ?? null)+ categoriesStore.primeFromCache((snap.categories as Categories) ?? null)+ walletsStore.primeFromCache((snap.wallets as Wallets) ?? null)+ userStore.primeFromCache((snap.user as UserSettingsCache) ?? null)+ currenciesStore.primeFromCache((snap.rates as Rates) ?? null)+ }+ performance.mark('cache:prime:end')+ performance.measure('cache:prime', 'cache:prime:start', 'cache:prime:end')}// Demo mode keeps its own localforage-backed cache (no backend).diff --git a/app/app/components/trns/useTrnsStore.ts b/app/app/components/trns/useTrnsStore.tsindex ebcd8ebe..16ec0782 100644--- a/app/app/components/trns/useTrnsStore.ts+++ b/app/app/components/trns/useTrnsStore.ts@@ -123,13 +123,21 @@ export const useTrnsStore = defineStore('trns', () => {returnwatchController?.abort()isLoaded.value = false // re-subscribe (e.g. different user) waits for a fresh emission+ let isFirstEmit = truewatchController = watchTable<Row>('SELECT * FROM trns', [], (rows) => {isLoaded.value = true// TEMP: keep cached data instead of wiping it with an empty first emission.if (!rows.length && hasItems.value)returnconst prev = items.value+ // Cold-start instrumentation: per-row materialize+transform cost vs the SQLite scan+ // (`ps:watch:trns` measure) - feeds the blob-cache architecture decision.+ const transformStart = isFirstEmit ? performance.now() : 0const next = prev ? reconcileTrns(prev, rows) : rowsToTrns(rows)+ if (isFirstEmit) {+ isFirstEmit = false+ performance.measure('trns:first-transform', { duration: performance.now() - transformStart, start: transformStart })+ }// reconcileTrns returns `prev` (same ref) when nothing changed - skip the rebuild// (this is the echo of our own optimistic write).if (next !== prev)