test: mark how long each persisted cache takes to load

This commit is contained in:
Linus Rath
2026-10-22 22:04:28 +02:00
parent 57ca1c8083
commit bdade8503d
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -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 {
+4
View File
@@ -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<S>(
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<S>;
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) {