Skip to content

singleton: migrate objectfled_diagnostics snapshot state (Tier 1d) #3487

Closed

Description

@zackees

Part of #3481 (Tier 1d).

Task

Wrap the 8 file-scope diagnostic-snapshot statics in src/platforms/arm/teensy/teensy4_common/drivers/objectfled/objectfled_diagnostics.cpp.hpp in fl::Singleton<T>.

Current state

SnapshotEvent s_events[MAX_EVENTS];        // L135
u8 s_eventCount = 0;                        // L136
u32 s_overflowCount = 0;                    // L137
u8 s_lastPins = 0;                          // L138
u8 s_lastPinCount = 0;                      // L139
BusyStateSnapshot s_busyState;              // L140
bool s_rxPinValid = false;                  // L141
u8 s_rxPin = 0;                             // L142

Approach

  1. struct ObjectFledDiagnosticsState { ... }; — collect all 8 into one struct.
  2. Route the snapshot(), event(), overflow() API through fl::Singleton<ObjectFledDiagnosticsState>::instance().s_events etc.
  3. Since the diagnostic buffer is written from ObjectFLED init code but NOT from an ISR (verify this — walk the call sites), the naive Singleton<T>::instance() pattern is safe here. If any writes come from an ISR, apply the pointer-cache pattern used in #TIER-2 issues.
  4. bash compile teensy41 --examples Blink — confirm the diagnostics storage is elided from Blink.

Acceptance criteria

  • File clean of SingletonElisionChecker warnings.
  • ObjectFLED regression tests pass (bench + autoresearch).
  • Blink flash size drops by ≈ sizeof(SnapshotEvent) * MAX_EVENTS + ~20 bytes on teensy41.

Activity

  1. added
    type: feature
    priority: medium
    platform: teensy
    area: drivers
    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.

    All 8 hits here are constant-initialized PODs. None warrant migration.

    objectfled_diagnostics.cpp.hpp:136-143 sits in namespace fl { namespace { (internal linkage). SnapshotEvent (L110) and BusyStateSnapshot (L103) are aggregates whose every member has a constant NSDMI (const char* stage = "", u32 gpr[4] = {0,0,0,0}), so the implicit default ctor is constexpr — static init, no .init_array entry. The array being ~12 KB is not the issue; it is already gc-eligible.

    Also note the file already carries FL_LINT_ALLOW_GLOBAL_FILE at L3 and therefore reports 0 checker hits today — this issue's own acceptance criterion is already satisfied. Wrapping in fl::Singleton would add a null-check to each of the 40+ access sites for no elision gain.

    Recommend closing as not-planned. See #3492 for the checker re-scope that would make this measurable.

  3. moved this from Triage to Done in FastLED Trackeron Aug 19, 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: driversplatform: teensypriority: mediumtype: feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions