[MEM] Reduce ESP32 BLE firmware RAM usage (#2294)
- Fix addLog buffer overflow; reduce LOG_BUFFER_SIZE 6096→3072, ROW_LENGTH 1024→512 - Lazy-allocate web console log buffer (saves ~3.5KB when console not active) - Stream WebUI responses in chunks to eliminate String heap allocations - NimBLE buffer tuning: ACL bufs 20→12, HCI hi bufs 30→15, MSYS1 blocks 12→8, MTU 256→185 - BLE adv report flow control 100→50, LWIP sockets 16→10 - BLE scan duplicate cache 200→100 (align with sdkconfig) - procBLETask stack 9500→8000 (788B headroom over measured peak) - Cap BLE device vector at 80 with LRU eviction of non-listed devices - Disable unused LWIP components: PPP, IPv6 autoconfig/DHCPv6 - Disable unused Arduino libs: SD, SD_MMC, FFat, LittleFS, NetBIOS Measured over 30 min A/B test vs development: freemem: 58,805 → 68,755 avg (+10KB) minmem: 5,988 → 15,780 (+9.8KB) msgprc/scnct: identical (656 msgs, 26 scans) msgblck: 0 on both branches No crashes or errors Co-authored-by: Florian <1technophile@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
4 files changed
+335
-388
No files matched your search
+18
-1
@@ -372,6 +372,23 @@ void createOrUpdateDevice(const char* mac, uint8_t flags, int model, int mac_typ
|
||||
}
|
||||
BLEdevice* device = getDeviceByMac(mac);
|
||||
if (device == &NO_BT_DEVICE_FOUND) {
|
||||
// Evict oldest non-listed device when at capacity
|
||||
if ((int)devices.size() >= MaxBLEDevices) {
|
||||
int oldestIdx = -1;
|
||||
unsigned long oldestTime = ULONG_MAX;
|
||||
for (int i = 0; i < (int)devices.size(); i++) {
|
||||
if (!devices[i]->isWhtL && !devices[i]->isBlkL && !devices[i]->connect &&
|
||||
devices[i]->lastUpdate < oldestTime) {
|
||||
oldestTime = devices[i]->lastUpdate;
|
||||
oldestIdx = i;
|
||||
}
|
||||
}
|
||||
if (oldestIdx >= 0) {
|
||||
THEENGS_LOG_TRACE(F("%.4s evict %s" CR), "BLE", devices[oldestIdx]->macAdr);
|
||||
delete devices[oldestIdx];
|
||||
devices.erase(devices.begin() + oldestIdx);
|
||||
}
|
||||
}
|
||||
THEENGS_LOG_TRACE(F("add %s" CR), mac);
|
||||
//new device
|
||||
device = new BLEdevice();
|
||||
@@ -889,7 +906,7 @@ void setupBTTasksAndBLE() {
|
||||
# if defined(USE_ESP_IDF) || defined(USE_BLUFI)
|
||||
14500,
|
||||
# else
|
||||
9500, /* Stack size in bytes */
|
||||
8000, /* Stack size in bytes */
|
||||
# endif
|
||||
NULL, /* Task input parameter */
|
||||
2, /* Priority of the task (set higher than core task) */
|
||||
|
||||
Reference in new issue
Block a user