Skip to content

singleton: migrate fl/stl/{ios,istream,ostream} state (Tier 1b) #3485

Closed as not planned

Description

@zackees

Part of #3481 (Tier 1b).

Task

Wrap the stream-state statics in src/fl/stl/ios.cpp.hpp, src/fl/stl/istream.cpp.hpp, and src/fl/stl/ostream.cpp.hpp in fl::Singleton<T> so unused stream storage is elided.

Approach

  1. Per file, identify the file-scope mutable state (typically default stream buffer, format flags, current width/precision).
  2. Wrap in a per-file state struct → fl::Singleton<Struct>::instance().field.
  3. If multiple state pieces logically belong together across the three files, consider a shared StreamState in fl/stl/streams_state.h.
  4. bash test --cpp — the STL tests exercise these directly.
  5. bash bloat before/after diff.

Acceptance criteria

  • All three files clean of SingletonElisionChecker warnings.
  • STL tests pass.
  • Storage confirmed elidable when streams are unused.

Activity

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

    All 6 hits are already annotated, and this file already demonstrates the pattern the whole tier should be measured against.

    The six carry FL_LINT_ALLOW_GLOBAL with written justifications (ios.cpp.hpp:11,13,15; ostream.cpp.hpp:8,11; istream.cpp.hpp:127), so the checker reports 0 hits here today — the acceptance criterion is already met. hex_t/dec_t/oct_t/endl_t are empty structs; ostream cout; uses = default with int mBase = 10;, so it is constant-initialized.

    More useful: istream.cpp.hpp:133 already does the right thing —

    istream_real& cin_real() { static istream_real instance; return instance; }
    

    That is a C++11 magic static: lazy construction with a compiler-generated thread-safe guard, which is strictly better than fl::Singleton's hand-rolled if (!ptr). Where lazy init genuinely is wanted, this is the pattern to copy.

    Recommend closing as not-planned. See #3492.

  3. zackees commented on Aug 20, 2026

    @zackees
    MemberAuthor

    Closing as not planned after re-validating the July audit against current master.

    The proposed fl::Singleton<T> migration would not satisfy the issue's stated optimization goal:

    • hex, dec, oct, and endl are public empty-struct manipulator objects with constant initialization.
    • cout is public named API state with a defaulted/constant-initialized small object; changing it to cout() would be source-breaking.
    • cin is likewise a small public stub, while its actual buffered istream_real storage is already lazy through a C++11 function-local static in cin_real().
    • The tree builds with per-data sections and linker garbage collection, so unreferenced constant-initialized POD data is already elidable. Wrapping it would add pointer storage and per-access checks without removing a dynamic initializer.
    • All six public globals have explicit FL_LINT_ALLOW_GLOBAL rationale, so SingletonElisionChecker has no outstanding finding in these files. Parent meta Meta: migrate namespace-scope globals to fl::Singleton<T> for --gc-sections elision #3481 is also closed.

    No code change is warranted, and no PR should be manufactured for a net-negative migration.

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

    area: corepriority: mediumtype: feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions