From b18b179fe5af3fdeebeade68b2bec9df6ad34be2 Mon Sep 17 00:00:00 2001 From: MarekZegare4 Date: Wed, 24 Jun 2026 21:39:46 +0200 Subject: [PATCH] perf(ui): shrink message-history rings to free heap QuickMsgScreen held the on-device scrollback in two RAM rings, each slot a full MSG_TEXT_BUF: CH_HIST_MAX=96 + DM_HIST_MAX=64 made the screen object ~31 KB on the heap (allocated at boot, never freed). On the Wio variant (MAX_CONTACTS=350, OFFLINE_QUEUE_SIZE=256) that left only ~3 KB free heap, so allocations in the input/menu path failed and entering Diagnostics hung the device. Halve the rings to CH_HIST_MAX=48 / DM_HIST_MAX=32, recovering ~14 KB of free heap (measured 3->17 KB). History is RAM-only (lost on reboot anyway); the cost is shorter on-device scrollback. Co-Authored-By: Claude Opus 4.8 --- examples/companion_radio/ui-new/QuickMsgScreen.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/companion_radio/ui-new/QuickMsgScreen.h b/examples/companion_radio/ui-new/QuickMsgScreen.h index ba0ebc16..ac6359ad 100644 --- a/examples/companion_radio/ui-new/QuickMsgScreen.h +++ b/examples/companion_radio/ui-new/QuickMsgScreen.h @@ -45,11 +45,12 @@ class QuickMsgScreen : public UIScreen { FullscreenMsgView _fs; int _unread_at_entry; // _ch_unread value when entering CHANNEL_HIST int _viewing_max_seen; // highest _hist_sel reached in current session - // Shared ring for all channels combined. Sized to comfortably exceed - // typical inter-visit accumulation; addChannelMsg() decrements the + // Shared ring for all channels combined. addChannelMsg() decrements the // matching _ch_unread when an entry is evicted so the badge can't claim - // unread messages that no longer exist in the ring. - static const int CH_HIST_MAX = 96; + // unread messages that no longer exist in the ring. Each slot carries a full + // MSG_TEXT_BUF, so this ring dominates the screen's RAM footprint — kept + // modest to leave heap headroom (see DM_HIST_MAX). + static const int CH_HIST_MAX = 48; // KEYBOARD KeyboardWidget* _kb; @@ -126,7 +127,8 @@ class QuickMsgScreen : public UIScreen { uint8_t attempt; // last attempt number sent (outgoing); next resend = attempt+1 uint8_t resends_left; // remaining auto-resends before the marker shows ✗ }; - static const int DM_HIST_MAX = 64; + // Each slot carries a full MSG_TEXT_BUF; kept modest to bound heap use. + static const int DM_HIST_MAX = 32; DmHistEntry _dm_hist[DM_HIST_MAX]; int _dm_hist_head, _dm_hist_count; int _dm_hist_sel, _dm_hist_scroll;