Batch per-frame persistence so busy meshes don't stall the UI isolate
Every received packet copy re-saved its channel's whole history, every unread change re-saved the channel list, and adverts/path records re-saved full contact and path-history blobs. Under load the SharedPreferences backlog starved the Dart event loop (frames and timers stopped), the radio's offline queue overflowed, and CPU stayed pinned after traffic ended. - Add CoalescedWrites: keeps the latest write per key and runs them once per window (750 ms; 5 s for path history). Writes start synchronously so stores still read the current scoped key. - Flush before the app is backgrounded, on disconnect, before switching radios, before the channel slot map changes, before channel history reloads, before deleteChannel drops a list, and before path history reloads an evicted contact. - Cap in-memory channel history at ChannelMessageStore.maxStoredMessages; storage already kept only that many, but the list grew unbounded during a session and every save grew with it. - Cache Contact.publicKeyHex and build pubKeyToHex from a hex-digit lookup; it was rebuilt on every equality/hash and per-advert contact scan. Load test (fake TCP radio, 350 contacts, 17 channels, 10-150 packets/s, Linux profile build): CPU at 10 packets/s 104% -> 45%, recovers to idle after traffic instead of staying at 160%, and queued messages drained went from 555 to 3237 over the same run.
This commit is contained in:
1 parent
eab1ad2964
commit
603172b3ec
10 files changed
+365
-29
No files matched your search
@@ -423,6 +423,15 @@ class _MeshCoreAppState extends State<MeshCoreApp> with WidgetsBindingObserver {
|
||||
state == AppLifecycleState.hidden) {
|
||||
unawaited(widget.imageCodecService.handleMemoryPressure());
|
||||
}
|
||||
// Batched message/contact writes must land before the OS can suspend or
|
||||
// kill a backgrounded app.
|
||||
if (state == AppLifecycleState.inactive ||
|
||||
state == AppLifecycleState.paused ||
|
||||
state == AppLifecycleState.hidden ||
|
||||
state == AppLifecycleState.detached) {
|
||||
unawaited(widget.connector.flushPendingWrites());
|
||||
unawaited(widget.pathHistoryService.flushPendingWrites());
|
||||
}
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
widget.connector.syncAppBadge();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user