Skip to content

perf(esp32p4): remove unnecessary Serial0 retention from Arduino framework startup #4892

Closed

Description

@zackees

Context

During #4887 native CDC link-map review, Arduino USB/USBMSC/USBCDC/TinyUSB HAL archive roots were eliminated, but modern P4 still retained HardwareSerial and String through an independent framework root.

Verified in Arduino-ESP32 3.3.11 cores/esp32/main.cpp:61-63: unless NO_GLOBAL_INSTANCES or NO_GLOBAL_SERIAL is defined, startup directly calls Serial0.setPins(gpioNumberToDigitalPin(SOC_RX0), gpioNumberToDigitalPin(SOC_TX0)). The P4 map shows main.o -> Serial0/HardwareSerial -> Stream::readString -> WString. Removing FastLED's console references cannot remove this root by itself.

Proposal

Investigate an upstream framework-compatible weak or lazy initialization boundary that configures UART0 only when a real application user links/initializes it. Determine whether the correct fix belongs in Arduino-ESP32 and whether fbuild packaging needs a version update. Preserve application Serial functionality and board pin defaults.

Acceptance criteria

  • RED -> GREEN: record a minimal modern P4 native-console ELF/map retaining Serial0 solely through startup, then demonstrate removal of that root with a concrete fix.
  • Normal Serial0.begin/write, default pins and explicitly selected pins continue to work; verify both native-first and Arduino-first order on supported hardware.
  • Compare matched no-Serial, explicitly-used Serial0, and native USB cases, reporting live symbol roots, flash/static RAM/runtime heap and SDK/core versions.
  • Check weak reference/archive extraction and global-constructor behavior; a weak declaration alone is not proof of elimination.
  • Link the upstream patch/issue and downstream package integration where needed. Document affected SDK/core/board scope rather than assuming all variants share this startup path.

Decisions

  • Do not force NO_GLOBAL_SERIAL or NO_GLOBAL_INSTANCES to manufacture a saving: those change application APIs.
  • Keep this framework-root work separate from fix(esp32): remove Arduino console retention with native SDK backends #4887's already removed FastLED/TinyUSB callback roots.
  • Weak/lazy initialization is a candidate, not a predetermined fix; choose only after preserving startup semantics.

Related issues

#4887 supplies the native P4 probe and link-map finding. Baseline integrated probe: IDF 5.5.5 / Arduino 3.3.11, 375,584 flash and 72,624 static RAM bytes; not a matched D32 size comparison.

Tracked under #4888.

Activity

  1. zackees commented on Oct 22, 2026

    @zackees
    MemberAuthor

    Current-source experiment confirms a concrete weak boundary can remove the startup root while preserving explicit Serial linkage. Core source is Arduino3.3.11 / IDF5.5.5, P4, current FastLED c1747a3.

    The candidate replaces main.cpp's direct Serial0.setPins call with a guarded weak undefined C hook. HardwareSerial.cpp supplies the strong hook with the original setPins operation. The hook does not extract the Serial archive member by itself; explicit application Serial use still extracts it and restores the same startup call. No NO_GLOBAL_SERIAL/NO_GLOBAL_INSTANCES setting or installed-SDK mutation was used.

    Matched pristine/candidate framework archives differ only by this two-file patch. Equal-length archive and build paths; real builds and bash bloat:

    Configuration Flash before / after Physical static RAM before / after
    Native UART, no app Serial 337610 / 315570 24592 / 23496
    Native USB CDC, no app Serial 380686 / 352268 73016 / 71888
    Explicit app Serial0 345102 / 345128 24592 / 24592

    Native-only candidates exclude sized Serial0, HardwareSerial methods and Stream::readString. The explicit Serial0 candidate retains them and the strong default-pin hook. The actual symbol-report verifier is RED before and GREEN after for the Serial root.

    One residual root remains independently: main -> chip-debug-report -> Esp.cpp -> WString retains a String constructor. An initial overly broad verifier correctly failed on it; this is not a claim that every Arduino String symbol disappeared. Existing #2886 tracks chip-debug-report suppression and its still-projected savings.

    Not complete: physical startup/default pins/explicit pins/native-first/Arduino-first/heap checks and durable production integration. Current fbuild honors framework HTTP(S) archive pins, but its native ESP32 build does not consume source replacement middleware. Scratch HTTP package serving proves the experiment, not a production integration. I am keeping this issue and parent #4888 open while completing those requirements.

  2. zackees commented on Oct 22, 2026

    @zackees
    MemberAuthor

    Implementation is integrated locally through an immutable framework source pin,
    paired with IDF 5.5.5 for esp32dev/esp32s3/esp32p4. Upstream patch:
    espressif/arduino-esp32#13010.

    Six matched P4 public-archive controls confirm build-summary savings of 22,040 B
    flash / 1,096 B static RAM for native UART and 28,418 / 1,128 B for native USB.
    Explicit Serial0 costs 26 B flash and unchanged static RAM. All six bash bloat
    reports independently confirm removal/preservation of the intended live owners;
    full totals and accounting differences are documented in the forthcoming PR.

    Physical classic ESP32 matched native-only AutoResearch recovers 612 B free heap
    (71,512 → 72,124). Explicit Serial0 retains the same 71,468 B free heap before and
    after. Both pairs pass five cold/settling/warm cycles with no retained per-cycle
    heap and valid integrity. Default pins, explicit GPIO16/17 changes/restoration,
    both initialization orders and exact alternating records pass the device probes.

    Full Python is green: 2,022 passed, 47 skipped, 2 expected failures, 3,280 subtests.
    Full lint passes. Final consolidated fixture verification is finishing before PR
    publication. Physical native USB runtime/heap remains explicitly unverified and
    will be handled under #4893; compile/link evidence is not a substitute for it.

  3. zackees commented on Oct 22, 2026

    @zackees
    MemberAuthor

    Published in PR #4898 (commit 1a32907). All three final consolidated AutoResearch modes passed five physical cycles each, normal S3/P4 Blink builds pass, full lint passes, and full Python reports 2,022 passed. Bloat/runtime details and upstream patch linkage are in the PR. Full stack/master CI and the separately tracked physical USB matrix #4893 remain pending.

  4. zackees commented on Oct 22, 2026

    @zackees
    MemberAuthor

    Closed: the Serial0 startup root lives in stock Arduino-ESP32 main.cpp and cannot be removed from FastLED with stock, unpatched SDKs (see #4898 closure). Tracked upstream at espressif/arduino-esp32#13010; revisit when a released core includes it.

  5. moved this from Triage to Done in FastLED Trackeron Oct 22, 2026
  6. zackees commented on Oct 23, 2026

    @zackees
    MemberAuthor

    Reopened: a stock-SDK fix exists after all; see #4911 and PR #4913.

  7. moved this from Done to Triage in FastLED Trackeron Oct 23, 2026
  8. moved this from Triage to Done in FastLED Trackeron Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions