perf(chat): debounce persisted writes and re-render only the streaming message

- the Zustand persist middleware serialized every saved session and wrote to AsyncStorage on each streamed token (appendToMessage -> set); writes are now debounced (400 ms) and flushed when the app leaves the foreground
- every token re-rendered every MessageBubble, re-parsing the Markdown of the whole conversation; rows are memoized so only the changed message renders (covered by MessageList.test.tsx)
This commit is contained in:
evandro committed 2026-10-10 04:28:38 -03:00
1 parent 200fb6afd7
commit 0e5b38fd15
6 files changed
+252 -13

No files matched your search

+2 -1
View File
@@ -1,4 +1,5 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import { appStorage } from '../store/debouncedStorage';
import { useAppStore } from '../store/useAppStore';
const state = () => useAppStore.getState();
@@ -172,7 +173,7 @@ describe('persistence', () => {
});
state().addMessage({ role: 'user', content: 'persist me' });
await new Promise((resolve) => setTimeout(resolve, 0));
await appStorage.flush();
const raw = await AsyncStorage.getItem('localaiapp-storage');
const persisted = JSON.parse(raw as string).state;