Skip to content

[Type-Erasure] chipsets: ClocklessControllerRuntime -- runtime-timing concrete class (#3244 Tier 2F) #3248

Open

Description

@zackees

Parent: #3244 (Phase 3 burn-down).

Goal

Introduce a ClocklessControllerRuntime concrete class that holds chipset timing (T1, T2, T3, RESET) and color order as runtime values instead of compile-time template parameters. Preserves the user-facing FastLED.addLeds<CHIPSET, PIN, ORDER>(...) API. Per-chipset vtable + per-EOrder PixelController specialization collapses to a single concrete class for any (chipset × order) combination on platforms where runtime dispatch is acceptable.

Reproduction (baseline)

Build a Blink-style sketch with multiple chipsets active:

bash bloat teensy40 --example Blink --top 15
# Look for fl::Channel::showPixels<PixelController<EOrder, lanes, mask>> entries.
# On Teensy 4 / AutoResearch (single chipset, GRB) the single instance is ~5.6 KB.
# A 4-chipset sketch (WS2812 + APA102 + SK9822 + WS2811) would pay 4× that = ~22 KB.

Acceptance

  • PR introduces fl::ClocklessControllerRuntime in fl/channels/ -- a non-templated CLEDController subclass that:
    • Holds ChipsetTiming (runtime u32 T1/T2/T3/RESET) and EOrder (runtime u8) members.
    • Implements show() / showColor() / init() as non-template virtual overrides.
    • Routes the actual transmission through the existing IChannelDriver singleton (fl::ChannelManager).
  • User-facing FastLED.addLeds<CHIPSET, PIN, ORDER>(...) API surface is unchanged. Internally it forwards to ClocklessControllerRuntime(pin, to_runtime_timing<TIMING>(), ORDER).
  • Gated via FL_USE_RUNTIME_CLOCKLESS (or similar). On ESP32/Teensy/RP2040/WASM the runtime variant becomes the default. AVR / LPC8xx / ESP8266 keep the existing template path (cycle-tight bit-banging requires compile-time timing -- see src/platforms/avr/clockless_avr.h:_dc<N> and src/platforms/arm/common/m0clockless_c.h's explicit instantiations).
  • Measured savings on at least one production sketch with ≥ 3 chipset specializations on Teensy 4 or ESP32-S3: ≥ 5 KB net flash drop.
  • No regression on single-chipset benchmarks for frame rate (the indirect call per pixel adds < 60 ns on Cortex-M7; should be invisible against WS2812's 30 µs per pixel).

Design reference

The FastLED rendering-side bloat audit run during #3235 documented:

Worst-case codegen examples in the repo: examples/Blink/Blink.ino and examples/RGBCalibrate/RGBCalibrate.ino instantiate ~40 chipset types each (most guarded by #if FORCE_SOFTWARE_PINS, but the compiler still sees them).

Risk

  • AVR — _dc<N> template-specialized cycle delays require compile-time constants. Mitigation: AVR keeps the legacy template path; runtime variant is opt-in.
  • LPC M0 / Cortex-M0+ — showLedData<HI_OFFSET, LO_OFFSET, TIMING, ORDER, WAIT_TIME> (in m0clockless_c.h) constexpr-folds timing into the cycle-tight loop. Same mitigation as AVR.
  • ESP8266 / older ARM — similar story for cycle-tight bit-bangers. Same mitigation.
  • RGBW emulation — RGBWEmulatedController / setRgbw() plumbing operates on CLEDController* and is unaffected.

Out of scope

Refs #3244, #3235 (Tier 2F).

Activity

  1. zackees commented on Jun 19, 2026

    @zackees
    MemberAuthor

    ⚠ /clud-fix intake gate failed (scope sanity). This comment is the deliverable, not a merged PR. If a session /goal hook references this issue URL, run /goal clear after reading — it will NOT auto-satisfy.

    What is going wrong

    Tier 2F (ClocklessControllerRuntime) is a multi-PR architectural change touching every chipset family. The rendering-side bloat audit catalogued the constraints:

    • 32 distinct TIMING_* structs in src/fl/chipsets/led_timing.h.
    • 29 user-facing *Controller template subclasses in src/chipsets.h.
    • AVR (_dc<N> template-specialized cycle delays) and LPC8xx (m0clockless_c.h showLedData<HI, LO, TIMING, ORDER, WAIT> explicit instantiations) require compile-time timing — runtime variant must be opt-in.
    • ESP32 RMT5 is already nearly fully type-erased post feat(channels): compile-time Bus binding via templated ChannelConfig (eliminates Channel API binary bloat) #2428; the leverage axis here is mostly per-EOrder PixelController specialization on cycle-counted platforms.

    The PR would need to:

    1. Introduce ClocklessControllerRuntime non-template class.
    2. Wire FastLED.addLeds<CHIPSET, PIN, ORDER>(...) to forward to it on opt-in platforms.
    3. Verify no regression on AVR / LPC / ESP8266 (template path stays).
    4. Validate frame rate on ESP32 / Teensy / RP2040 / WASM (indirect call per pixel adds latency).
    5. Pick a target sketch with ≥3 chipset specializations to demonstrate savings.

    That's not a single session-sized PR. The audit explicitly called it "medium-hard, different leverage axis (per-chipset, not per-Sig)."

    Reproduction status

    Baseline measurement command in the issue body works:

    bash bloat teensy40 --example Blink --top 15
    # Look for fl::Channel::showPixels<PixelController<EOrder, ...>> entries
    

    Symptom is falsifiable. Only "small, well-bounded feature" criterion fails.

    Planned fix (what would unblock this sub-issue)

    Decompose into phases:

    1. Phase A: file a separate sub-issue for ClocklessControllerRuntime as a standalone new class (no integration). Single new file. Bounded.
    2. Phase B: file a separate sub-issue introducing the FL_USE_RUNTIME_CLOCKLESS macro + addLeds dispatch fork. Single header touch + one platform's chipset.h. Bounded.
    3. Phase C: extend to remaining platforms (ESP32, Teensy, RP2040, WASM) one at a time. Each its own sub-issue with its own benchmark validation.

    Each phase is small enough to pass intake independently.

    Recommendation

    Skip this sub-issue in the current /clud-fix run. When ready:

    1. Decide whether the indirect-call-per-pixel cost is acceptable on Cortex-M0+ / -M4 hot paths (benchmark first).
    2. File Phases A-C as separate sub-issues against META: memory & flash reduction -- Phase 3 burn-down (continues #3235) #3244.
    3. Re-invoke /clud-fix on META: memory & flash reduction -- Phase 3 burn-down (continues #3235) #3244 — the new sub-issues will be picked up.
  2. zackees commented on Jun 19, 2026

    @zackees
    MemberAuthor

    ⚠ /clud-fix intake gate result: scope-sanity fail → investigation report deliverable. This comment is the deliverable for this session pass, not a merged PR. If a session /goal hook references this issue URL, run /goal clear after reading — it will NOT auto-satisfy.

    What is going wrong

    #3248 is a well-specified issue (concrete repro, falsifiable ≥5 KB target, explicit acceptance checklist) but it fails the /clud-fix "scope sanity" intake bullet: the ask is a multi-day architectural refactor, not a small well-bounded change. Trying to one-shot it in a single agent session would either:

    1. Ship a partial implementation that breaks the build on one of {AVR, LPC, ESP32, Teensy, M0, ESP8266, WASM, host}, or
    2. Skip the platform-fork preservation that the acceptance bullets explicitly require, or
    3. Skip the ≥5 KB measurement on a ≥3-chipset Teensy 4 / ESP32-S3 sketch, leaving the issue unverified.

    None of those are acceptable per the project's "No half-finished implementations" rule (CLAUDE.md → Core Principles).

    Scope breakdown — why this is multi-PR work

    The acceptance checklist composes five separable PRs:

    Phase Scope Risk Estimated PRs
    A Add fl::ClocklessControllerRuntime (non-templated CLEDController subclass) holding ChipsetTiming + EOrder as runtime members. Route through existing IChannelDriver (the post-#2428 seam exists). Gated FL_USE_RUNTIME_CLOCKLESS=0 by default. Host-only unit tests. Low 1 PR
    B Wire to_runtime_timing<TIMING>() consumers + FastLED.addLeds<CHIPSET,PIN,ORDER> forwarding path. Keep template path as the active default. Cross-platform compile verification. Medium 1 PR
    C Flip default to runtime on ESP32 / Teensy 4 / RP2040 / WASM only. AVR / LPC M0 / ESP8266 stay on template path (cycle-tight bit-banging requires compile-time constants — _dc<N> in clockless_avr.h, showLedData<...> in m0clockless_c.h). Per-platform compile matrix verification. High 1 PR
    D Frame-rate regression bench on single-chipset Teensy 4 (acceptance bullet "indirect call per pixel < 60 ns" requires a measurement, not a guess). Low 1 PR
    E Multi-chipset bloat measurement on Teensy 4 or ESP32-S3 (≥5 KB target). If hit → close #3248. If short → publish findings and decide next step (kitchen-sink benchmark vs. flag flip). Low 1 PR

    That's a Tier 2F sub-meta in its own right.

    Touched surface (per-file count, approx)

    • src/chipsets.h — 29 *Controller template subclasses; each needs a forwarder to the runtime variant when flag is set.
    • src/fl/chipsets/led_timing.h — 32 TIMING_* structs; the to_runtime_timing<TIMING>() helper already exists per the audit, but consumer wiring is missing.
    • src/FastLED.h — addLeds<> template forwarders.
    • src/platforms/{avr,arm/lpc,arm/common,esp/8266}/... — keep template path intact (5-6 files touched only to gate the runtime variant out).
    • src/platforms/{esp/32,arm/common/m4,arm/common/m7,rp2040,wasm}/... — opt into the runtime variant on flag-on (5-6 files).
    • New: src/fl/channels/clockless_controller_runtime.{h,cpp.hpp}.
    • New: tests/fl/channels/clockless_controller_runtime.hpp.

    Touching ~30 files per phase × 5 phases × keeping the cross-platform compile matrix green is the work, not the design.

    Reproduction status

    Baseline reproduction works:

    bash bloat teensy40 --example Blink --top 15
    

    Expected hot symbol: fl::Channel::showPixels<PixelController<EOrder, lanes, mask>> (~5.6 KB single-instance, scales linearly with distinct (chipset × order) combinations). Issue body documents this from prior audit.

    Planned fix — recommended ordering for whoever picks this up

    1. Start with Phase A. Land the ClocklessControllerRuntime skeleton with the gate FL_USE_RUNTIME_CLOCKLESS=0 by default, host-side unit tests, and zero changes to the existing template path. This is a low-risk infrastructure-only PR that creates the seam.
    2. Then Phase B. Wire to_runtime_timing<TIMING>() and the FastLED.addLeds<> forwarders behind the same off-by-default gate. Cross-platform compile matrix is the verification.
    3. Then Phase C. Flip the gate on for the four "big memory" platforms. AVR / LPC M0 / ESP8266 / older ARM stay opted out per the acceptance bullet.
    4. Then Phase D. Run the Teensy 4 frame-rate bench (bash profile <function> per project tooling) on a single-chipset sketch. Acceptance requires showing the indirect-call overhead is below the WS2812 per-pixel budget.
    5. Then Phase E. Multi-chipset bloat measurement (RGBCalibrate or a fresh kitchen-sink sketch that names 3+ chipsets). If ≥5 KB → close [Type-Erasure] chipsets: ClocklessControllerRuntime -- runtime-timing concrete class (#3244 Tier 2F) #3248. If short → expand or refine.

    Each phase is its own merge-able PR and each verifies independently.

    Open questions for the next agent or maintainer

    1. Is splitting [Type-Erasure] chipsets: ClocklessControllerRuntime -- runtime-timing concrete class (#3244 Tier 2F) #3248 into 5 sub-PRs acceptable, or should this remain a single Tier 2F item that's just slow to land? Filing the phases as separate child issues under [Type-Erasure] chipsets: ClocklessControllerRuntime -- runtime-timing concrete class (#3244 Tier 2F) #3248 would let /clud-fix (or a human) iterate through them.
    2. Which existing sketch is the canonical multi-chipset Teensy 4 benchmark? Acceptance mentions "production sketch with ≥3 chipset specializations" but doesn't name one. RGBCalibrate has many #if-guarded chipsets; whether the compiler sees them all in a single build is the actual question.
    3. Is the FL_USE_RUNTIME_CLOCKLESS flag name acceptable, or should it use the existing FL_PLATFORM_HAS_LARGE_MEMORY family? Acceptance bullet says "or similar" — clarification needed before Phase A.

    What I'm NOT doing in this pass

    • Not opening a one-shot PR that would land partial scope (per "No half-finished implementations").
    • Not filing the 5 phase sub-issues automatically (the "Manufacturing meta-level work" failure mode applies — the next agent / human should make that call after design discussion).
    • Not flipping any gate, not touching any platform file. This comment is the deliverable.

    Meta loop state

    Continuing the #3244 meta loop on the easier sub-issues this iteration. #3248 stays open as-is for a focused multi-PR followup.

    Refs #3244, #3235.

  3. zackees commented on Aug 20, 2026

    @zackees
    MemberAuthor

    Deferred under the active bug-burn-down policy after re-validating the implementation surface against current master.

    Current evidence:

    • src/fl/chipsets/led_timing.h still provides to_runtime_timing<TIMING>(), but the tree contains no ClocklessControllerRuntime implementation and no FL_USE_RUNTIME_CLOCKLESS integration gate.
    • The two prior scope audits agree that acceptance requires five independently verifiable phases: runtime controller, API forwarding, platform-by-platform gating/defaults, single-chipset latency benchmarking, and a 3+ chipset flash benchmark.
    • The compile-time paths on AVR/LPC/ESP8266/older ARM must remain intact, while ESP32/Teensy/RP2040/WASM each require explicit integration and cross-platform validation.
    • Acceptance also requires attached Teensy 4 or ESP32-S3 performance/flash evidence; the current environment has neither target attached.

    This is therefore a genuine multi-PR architecture and hardware-benchmark program, not a bounded bug-fix PR. The issue remains open and is excluded from the actionable burn-down until the deferred label is deliberately removed.

    Restart criteria:

    1. Split Phases A-E into bounded child issues with one platform/default change per PR.
    2. Select and preserve a canonical 3+ chipset production benchmark.
    3. Provide Teensy 4 or ESP32-S3 hardware for the latency and >=5 KB flash acceptance measurements.
    4. Remove deferred only when those prerequisites are available.
  4. added
    deferred
    on 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

    deferred

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions