From bdade8503deea70d83bcaa236f70a8f045994b66 Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Thu, 22 Oct 2026 04:28:39 +0200 Subject: [PATCH] test: mark how long each persisted cache takes to load --- src/lib/perf-marks.ts | 2 +- src/stores/persist-storage.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/perf-marks.ts b/src/lib/perf-marks.ts index 7bfd634e..3bcbeadd 100644 --- a/src/lib/perf-marks.ts +++ b/src/lib/perf-marks.ts @@ -9,8 +9,8 @@ import { Platform, Settings } from 'react-native'; function readEnabled(): boolean { - if (Platform.OS !== 'ios') return false; try { + if (Platform.OS !== 'ios') return false; const value = Settings.get('perfMarks') as unknown; return value === true || value === 'YES' || value === 'true' || value === 1 || value === '1'; } catch { diff --git a/src/stores/persist-storage.ts b/src/stores/persist-storage.ts index 3a956f7e..37386d0a 100644 --- a/src/stores/persist-storage.ts +++ b/src/stores/persist-storage.ts @@ -16,6 +16,7 @@ import { AppState } from 'react-native'; import AsyncStorage from '@react-native-async-storage/async-storage'; +import { perfMark } from '../lib/perf-marks'; import type { PersistStorage, StorageValue } from 'zustand/middleware'; /** How long a store's write waits to take in further changes. */ @@ -93,9 +94,12 @@ export function createPersistStorage( return { getItem: async (name) => { try { + const t0 = Date.now(); const raw = await AsyncStorage.getItem(name); if (raw === null) return null; + const t1 = Date.now(); const value = JSON.parse(raw) as StorageValue; + perfMark('hydrate', { store: name, readMs: t1 - t0, parseMs: Date.now() - t1, kb: Math.round(raw.length / 1024) }); slotFor(name).stored = raw; return value; } catch (err) {