Skip to content

singleton: sweep small (<=2-hit) files (Tier 1e) #3488

Closed

Description

@zackees

Part of #3481 (Tier 1e).

Task

Mop up the long tail of files with 1–2 SingletonElisionChecker hits each. Each fix is 15 minutes. Doing them as a single sweep is more efficient than one PR per file.

In-scope

Files with ≤2 violations after Tier 0 tooling narrows the set. Rough candidates from the current scan:

Out of scope

  • Files with ≥3 hits (get their own Tier 1 or Tier 2 issue).
  • Public API surface (FastLED in FastLED.cpp.hpp — untouchable).
  • Host-only stubs (platforms/stub/, platforms/wasm/ — not on-device bloat).

Approach

  1. After lint: wire SingletonElisionChecker into bash lint (warn-only) #3482 (checker registration) is merged, dump the full SingletonElisionChecker warn output.
  2. Sort by hit count ascending, take all files with ≤2 hits and no explicit exclusion.
  3. Wrap each in a single-file-scoped Singleton<State>::instance().
  4. One PR per module (fx/, sensors/, ...) — not one PR per file. Group by directory.

Acceptance criteria

  • All ≤2-hit files clean of SingletonElisionChecker warnings.
  • Remaining warnings are only the ≥3-hit files owned by other Tier issues.

Activity

  1. added
    type: feature
    priority: low
    area: core
    on Jul 1, 2026
  2. zackees commented on Jul 28, 2026

    @zackees
    MemberAuthor

    Audited against the finding in #3754 / #3486: fl::Singleton elision pays off only for objects with dynamic initialization (those register .init_array entries that pull in a ctor and resist --gc-sections). It does nothing for constant-initialized PODs — builds already pass -ffunction-sections -fdata-sections (ci/boards.py:795), so those are already dropped when unreferenced. For PODs the wrap is a net loss: storage grows by a T*, every access gains a null-check, and constant-initialization (race-free) is replaced by Singleton<T>::instance()'s hand-rolled if (!ptr), which bypasses the C++11 magic-static guard.

    12 hits across the current ≤2-hit set, all constant-initialized PODs. One target has moved.

    src/fl/sensors/pir.cpp.hpp:16 int g_counter = 0; is the canonical net-loss case: 4 bytes already gc-able, and the wrap would make it 8-12 plus a branch per access.

    flowfield.cpp.hpp has moved to src/fl/fx/2d/ and now has zero hits (only static constexpr i32 FP_ONE at L484).

    Remainder, all the same class: FastLED.cpp.hpp:70 (declared out of scope by this issue anyway), fl/stl/asio/http/server.cpp.hpp:680,947, fl/test/fltest.cpp.hpp:231-232, platforms/arm/lpc/platform_time_lpc.cpp.hpp:17-18, platforms/avr/attiny/clockless_blocking.cpp.hpp:16, platforms/shared/coroutine_context.cpp.hpp:23, platforms/wasm/audio_input_wasm.cpp.hpp:20 (host-only, out of scope).

    Worth calling out: coroutine_context.cpp.hpp:23 is itself the backing pointer of a hand-rolled singleton — a permanent-allowlist entry, not a migration target.

    Recommend closing as not-planned, or re-scoping to an annotation-only sweep if you want the warn stream quiet. See #3492.

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

    area: corepriority: lowtype: feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions