Skip to content

perf(stl): ThreadLocalReal stores an inline default T, doubling SingletonThreadLocal RAM on ESP32/host #5304

Closed

Description

@zackees

Problem

On multithreaded targets (ESP32, host) ThreadLocalReal<T> (src/fl/stl/thread_local.h:~141) stores an inline T mDefaultValue in addition to the per-thread heap copy. For SingletonThreadLocal<T> with a large T, this roughly doubles RAM: measured with xtensa-esp32 gcc 8.4, a 989 B T costs 996 B static storage plus ~990 B heap per thread on first access (never freed for singletons), and each access goes through a 198 B accessor (vs 39 B for Singleton).

Proposed solution

  • Don't store a full inline default T when the default is just value-initialization: e.g. store the default only when a non-default value was supplied, or construct per-thread copies with T() directly.
  • Keep API and semantics (per-thread copy initialized from the default) unchanged; unit test that per-thread values start at the provided default and are independent.
  • Host regression check that sizeof(ThreadLocal<Big>) with no explicit default is not O(sizeof(Big)).

Activity

  1. added
    type: bug
    on Nov 20, 2026
  2. added
    sanitized
    on Nov 20, 2026
  3. moved this from Triage to Done in FastLED Trackeron Nov 20, 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

    sanitizedtype: bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions