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
@@ -497,8 +497,16 @@ String ackHashToHex(int ackHash) {
|
||||
}
|
||||
|
||||
// Helper to convert public key to hex string
|
||||
const String _hexDigits = '0123456789abcdef';
|
||||
|
||||
String pubKeyToHex(Uint8List pubKey) {
|
||||
return pubKey.map((b) => b.toRadixString(16).padLeft(2, '0')).join();
|
||||
final codes = Uint8List(pubKey.length * 2);
|
||||
for (var i = 0; i < pubKey.length; i++) {
|
||||
final b = pubKey[i];
|
||||
codes[i * 2] = _hexDigits.codeUnitAt(b >> 4);
|
||||
codes[i * 2 + 1] = _hexDigits.codeUnitAt(b & 0x0F);
|
||||
}
|
||||
return String.fromCharCodes(codes);
|
||||
}
|
||||
|
||||
// Helper to convert hex string to public key
|
||||
|
||||
Reference in new issue
Block a user