From 55166d4773f75bba1a0e622c7f4b76ad38b1c473 Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Sun, 12 Jul 2026 01:05:16 +0200 Subject: [PATCH] perf(repeater): drop duplicate per-packet SHA-256 from rxlog capture captureRx() ran calculatePacketHash() (SHA-256) on every received frame in the logRx hot path. The mesh core already computes that SHA once per frame in hasSeen() during routing, so the analyzer was doubling the crypto load on the radio-shared main loop for no benefit. Replace pkt_hash with a cheap FNV-1a over (type||payload): same purpose (dedup / correlation across nodes running this FW), a fraction of the CPU. RAM-only, no flash writes, still main-loop (not ISR) -- so this does not by itself explain BLE link drops (those match the known SoftDevice/LoRa coexistence instability the BLE watchdog already guards), but it removes the one real RX-path cost the analyzer added. Co-Authored-By: Claude Opus 4.8 --- examples/simple_repeater/MyMesh.cpp | 14 +++++++++++--- examples/simple_repeater/MyMesh.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 43477699..d426ee37 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -164,9 +164,17 @@ void MyMesh::captureRx(const mesh::Packet* pkt) { r->seq = rxlog_next_seq++; if (rxlog_next_seq == 0) rxlog_next_seq = 1; // wrap guard (seq 0 reserved for empty) r->when = getRTCClock()->getCurrentTime(); - uint8_t h[MAX_HASH_SIZE]; - pkt->calculatePacketHash(h); - memcpy(&r->pkt_hash, h, 4); + // Cheap deterministic frame id via FNV-1a over (type || payload) -- NOT a + // per-packet SHA-256. The mesh already computes the crypto packet hash once + // per frame (hasSeen); calling calculatePacketHash() here too would double + // the crypto load on the radio hot path for no benefit. FNV is a fraction of + // the cost and still lets nodes running this FW dedup / correlate the same + // frame. (This is NOT the MeshCore SHA packet-hash.) + uint32_t fnv = 2166136261u; + uint8_t t = pkt->getPayloadType(); + fnv = (fnv ^ t) * 16777619u; + for (uint16_t k = 0; k < pkt->payload_len; k++) fnv = (fnv ^ pkt->payload[k]) * 16777619u; + r->pkt_hash = fnv; r->snr = pkt->_snr; r->rssi = (int8_t) pkt->getRSSI(); r->header = pkt->header; diff --git a/examples/simple_repeater/MyMesh.h b/examples/simple_repeater/MyMesh.h index b7618bfb..7f8dc8c7 100644 --- a/examples/simple_repeater/MyMesh.h +++ b/examples/simple_repeater/MyMesh.h @@ -119,7 +119,7 @@ struct HeardNode { struct RxLogRec { uint32_t seq; // monotonic capture sequence (0 = empty slot; also the paging cursor) uint32_t when; // epoch - uint32_t pkt_hash; // low 4 bytes of the packet hash (dedup / cross-observer correlate) + uint32_t pkt_hash; // FNV-1a of (type||payload) -- cheap dedup / cross-observer id (NOT the SHA packet-hash) int8_t snr; // x4 int8_t rssi; // dBm uint8_t header; // raw header byte (route|type|ver)