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
@@ -858,6 +858,8 @@ void main() {
|
||||
svc.recordPathResult(pubKey, sel, success: true, successIncrement: 0.5);
|
||||
}
|
||||
await _flush();
|
||||
// Saves are batched; a restart only follows a flush (app backgrounded).
|
||||
await svc.flushPendingWrites();
|
||||
|
||||
final fresh = PathHistoryService(storage);
|
||||
fresh.recordPathResult(pubKey, sel, success: true, successIncrement: 0.5);
|
||||
@@ -871,6 +873,7 @@ void main() {
|
||||
test('getRecentPaths load does not drop a concurrent add', () async {
|
||||
final pubKey = _hex('k004');
|
||||
await _seed(svc, pubKey, pathBytes: [0x01], weight: 1.0);
|
||||
await svc.flushPendingWrites();
|
||||
|
||||
final fresh = PathHistoryService(storage);
|
||||
fresh.getRecentPaths(pubKey);
|
||||
|
||||
Reference in new issue
Block a user