Skip to content

perf(esp32dev): Wi-Fi probe keeps libnet80211 live (+1.3 KB RAM) despite weak linking #4791

Closed

Description

@zackees

Problem

On esp32dev, every sketch on master links ~1.3 KB of Wi-Fi BSS (s_wifi_nvs, 1,308 B, libnet80211.a(ieee80211_nvs.o)) plus ~0.3 KB of net80211 flash. 3.10.3 did not. This is more than half of esp32dev's RAM regression (Blink +2,442 B, SPI +2,627 B). ESP32-S3 is unaffected.

Root cause (from the linker map)

NetworkDetector::isWiFiActive() (src/platforms/esp/32/drivers/rmt/rmt_5/network_detector.cpp.hpp:84-104) already declares esp_wifi_get_mode FL_LINK_WEAK and checks it against nullptr. A weak undefined reference never extracts an archive member, but on Arduino-ESP32 3.3.11 (esp32dev) the core extracts the net80211 members anyway:

main.o (delay) → esp32-hal-misc (initArduino) → esp32-hal-bt (_btInUse_default)
  → libbt bt.c.obj (esp_bt_mem_release) → libesp_phy phy_init (esp_phy_rf_get_on_ts)
  → libesp_wifi wifi_init (s_wifi_mac_time_update_cb) → libnet80211 supplicant
  → ieee80211_api (esp_wifi_get_mode) / ieee80211_nvs (g_wifi_nvs)
  • 3.10.3: the same members are extracted, but nothing references them, so --gc-sections drops their code and BSS.
  • Master: the weak symbol always resolves, so isWiFiActive() calls esp_wifi_get_mode and keeps them live.
  • ESP32-S3: phy_init does not pull wifi_init, so the weak symbol stays null and costs nothing.

Callers include FastLED.cpp.hpp:354, fl/channels/manager.cpp.hpp:507, fl/channels/driver.cpp.hpp:51 and channel_driver_rmt.cpp.hpp:747.

Proposed fix

Gate the Wi-Fi probe on a weak reference to a symbol that is only extracted when the application really brings Wi-Fi up. Candidates: IDF esp_netif_create_default_wifi_sta (libesp_wifi.a(wifi_default.c.obj)) or Arduino WiFiGenericClass code. Only call esp_wifi_get_mode when that gate is non-null. The fallback, if no clean gate symbol exists, is an opt-in FASTLED_NETWORK_AWARE define.

Acceptance

  • esp32dev Blink map contains no ieee80211_nvs.o BSS. Dashboard RAM drops about 1.3 KB.
  • A Wi-Fi sketch (Arduino WiFi.begin and IDF esp_wifi_start) still reports isWiFiActive() == true, checked via map and on-device.
  • No change on S3, C3 or C6.

Data: https://fastled.github.io/dashboard/ (master 18669e6 vs 3.10.3, fbuild 2.5.38), symbol-level bloat reports linked from each dashboard point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform: esp32priority: hightype: regression

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions