Skip to content

LPC845 bloat: fl::string::trim() is 2.9 KB single function; basic_string::operator[] 1.5 KB; sstream::operator<<(char) 1.25 KB #3078

Closed

Description

@zackees

Symptom

Two fl::string / fl::basic_string methods register as single-function bloat hotspots on LPC845 LowMemory + FASTLED_LPC_RX_SCT_WS2812=1:

2,966 bytes  fl::string::trim() const
1,572 bytes  fl::basic_string::operator[](unsigned int) const
1,250 bytes  fl::sstream::operator<<(char)
  686 bytes  fl::string_n<64u>::string_n()
                              ------
~6.5 KB combined (~8% of .text)

trim() at 2,966 bytes is the most surprising — even a generous double-loop implementation should sit under 200 bytes on Cortex-M0+ with -Os. A function this large almost certainly indicates either an inlined factory chain (constructing a new string + copying + holder reference-counting) or an exception-handling unwind cleanup explosion.

Why this is surprising

fl::string is the centerpiece of LPC8xx text handling (JSON parsing, RPC method names). It has been through fefca7b8c1 (drop StrN template) and is expected to be lean. The numbers above suggest some non-obvious codegen multiplier — likely:

  • operator[](unsigned int) const doing bounds-checking + control-block ref-count traversal in a non-tail-call shape
  • trim() const returning a new string (forcing allocate + copy + holder construction) instead of returning a string_view

Possible directions

  1. Have trim() return fl::string_view instead of a new owned fl::string — leaves the original buffer untouched, avoids the allocate+copy+holder cascade.
  2. Look at basic_string::operator[](unsigned int) const for unnecessary control-block traversal — it is a read-only access of a single char, should be a load+return.
  3. fl::sstream::operator<<(char) at 1.25 KB suggests the streaming pipeline is doing format-string-style dispatch for a single-char append. Likely a candidate for direct buffer-write specialization.

Repro

Same as parent meta.

Acceptance

  • fl::string::trim() const drops below 500 bytes on LPC845-BRK LowMemory build
  • fl::basic_string::operator[](unsigned int) const drops below 200 bytes
  • fl::sstream::operator<<(char) drops below 200 bytes
  • Combined string bloat under 1.5 KB total on LPC845-BRK LowMemory build

Related

  • fbuild#594 — tooling gap
  • Meta: (will link)

Activity

  1. zackees commented on Jun 15, 2026

    @zackees
    MemberAuthor

    Tracked under meta #3079 (LPC845 64 KB flash bloat hunt) alongside three sibling bloat sub-issues and the FastLED/fbuild#594 tooling-gap dependency.

  2. zackees commented on Jun 15, 2026

    @zackees
    MemberAuthor

    Closing as filed in error — retraction.

    The 9.5 KB / 2.9 KB / 1.5 KB / 1.25 KB numbers reported in this issue are wrong. They came from a one-off Python script that parsed firmware.map for symbol addresses, then attributed the byte-delta to the next symbol's address as the size of the symbol. That methodology is invalid: the linker map only lists a sparse subset of symbols; the address gap between two listed symbols often contains many unlisted intermediates. My parser attributed all that intervening code to the visible neighbor.

    Verified by running the real arm-none-eabi-nm --print-size --size-sort on the actual ELF (after forcing the link with a temporary LD-script bump per FastLED/fbuild#594):

    Symbol Claimed Actual nm size
    fl::CRGB::computeAdjustment 9,516 B 54 B (0x36)
    fl::string::trim() const 2,966 B 164 B (0xa4)
    fl::basic_string::operator[](unsigned int) 1,572 B 32 B (0x20) + 22 B const = 54 B
    fl::sstream::operator<<(char) 1,250 B 28 B (0x1c)

    All four targets in this issue are within normal small-function sizes. There is no bug here.

    The correct top contributors for the LPC845 LowMemory + RX_SCT_WS2812 build are tracked under the revised meta #3079. The reproducibility / methodology gap that made this mistake easy to publish is tracked in FastLED/fbuild#594 (no bash bloat path for arm-none-eabi today; manual parsing was the only option).

    Apologies for the noise.

  3. moved this from Triage to Done in FastLED Trackeron Jun 15, 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