Skip to content

perf(channels): bind every constant typed chipset to its one encoder (#5162) - #5413

Merged
zackees merged 1 commit into
masterfrom
fix/5162-channels-typed-fast-path
Nov 22, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/5162-channels-typed-fast-path

Conversation

@zackees

@zackees zackees commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Closes #5162

Summary

#5163 bound the pixel encoder at the typed add<Bus>() boundary, but only for WS2812. Every other constant chipset (TM1812, TM1908, UCS7604 and all SpiChipsetConfig chipsets) still fell back to the shared selector, which links every encoder. This PR extends #5163's mechanism to all of them, so a typed add<Bus>() with a constant chipset links only its own encoder.

How

  • EncoderAvailability gets one out-of-line getter per encoder (apa102(), ucs7604(), ...). Each getter references only its own encoder and returns nullptr when the library disables it. FASTLED_DISABLE_UCS7604 / FASTLED_DISABLE_SPI_CHIPSETS therefore stay library-only decisions, which keeps the ODR fix from Channels API: cut add<Bus>() flash overhead vs addLeds<> by 50% (ESP32-C6: +47 KB) #5157.
  • The chipset-to-encoder mapping lives in one inline EncoderAvailability::dispatch<Binder>() template. The erased path's select() uses it with a binder that calls the getter. TypedChannel::factoryFor() uses it with a binder that returns &createBound<getter>. A constant chipset folds to one factory, and an unknown chipset falls back to the shared selector, as before.
  • The isWS2812 special case is gone. WS2812 now takes the same path as the other chipsets.
  • No changes to channel.cpp.hpp or to any encoding loop.

ESP32-C6 flash (bash bloat esp32c6 --build, image flash / attributed RAM)

Sketch master this PR
A addLeds<APA102, 3, 4, BGR> 353,538 / 18,074 353,538 / 18,074
C add<Bus::AUTO, SpiChipsetConfig>(apa102) 390,492 / 18,830 377,422 / 18,775
APA102 C - A +36,954 +23,884 (-35.4%)
A addLeds<UCS7604HD, 3, GRB> 366,596 / 18,747 366,596 / 18,747
C add<Bus::AUTO>(makeClockless<TIMING_UCS7604_800KHZ>) 390,560 / 18,830 383,732 / 18,830
UCS7604 C - A +23,964 +17,136 (-28.5%)
C add<Bus::AUTO>(WS2812) 378,240 / 18,775 378,312 / 18,775 (+72)

Linked Channel::encode* symbols, from the bloat report.json:

  • master, APA102 C and UCS7604 C: all 14 encoders.
  • this PR, APA102 C: encodeAPA102 only. UCS7604 C: encodeUCS7604 only.

The sketches are scratch copies outside examples/, built in git archive trees of master and of this branch.

Tests

  • RED first: the new [#5162] constant typed chipsets bind only their own encoder case in tests/unit/fl/channels/encoder_availability.cpp failed on master. Every non-WS2812 chipset resolved to the shared selector. The case checks, for every clockless encoder and all 16 SPI chipsets, that factoryFor() is not the shared selector, that chipsets sharing an encoder share a factory (the APA102/DotStar/HD107 and SK9822 families, the three UCS7604 modes), and that distinct encoders get distinct factories. It also checks that the ChipsetVariant overload used by add<B>(ChannelConfig) agrees.
  • The existing Channels API: cut add<Bus>() flash overhead vs addLeds<> by 50% (ESP32-C6: +47 KB) #5157 byte-parity tests (channel.cpp: every clockless encoder and all 16 SPI variants, typed vs erased) and the conflicting-macro availability test now run through the new bound factories.
  • bash test encoder_availability and bash test fl_channels_channel, quick and --debug: pass.
  • bash test --cpp: 375/375 unit and 97/97 examples pass. bash lint: pass.

Limitations

  • The typed WS2812 path costs +72 B: the factory now calls a one-instruction library getter instead of loading the encoder address inline.
  • When the chipset is not a compile-time constant on the typed path, the inlined mapping keeps all bound factories (one small thunk per encoder). The erased add(cfg) path is unchanged.

Summary by CodeRabbit

  • Improvements
    • LED chipset configurations now resolve more consistently to their matching encoder implementations across clockless and SPI-based options.
    • Chipsets that share an encoder continue to use the same implementation, while distinct encoders remain separately selectable.

@zackees
zackees enabled auto-merge November 22, 2026 04:43
@github-actions github-actions Bot added the sanitized Title, body and conversation screened; review text requires separate screening. label Nov 22, 2026
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 1

Validation error: Unrecognized key: "enabled" at "reviews.pre_merge_checks"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

No actionable comments were generated in the recent review.

Walkthrough

Typed channel factory selection now uses chipset dispatch to bind factories to encoder-specific implementations. EncoderAvailability provides getter functions and dispatch mappings for clockless and SPI chipsets. Tests verify factory resolution and sharing across typed and erased configurations.

Changes: Typed encoder binding

Layer / File(s) Summary
Chipset-to-encoder dispatch
src/fl/channels/encoder_availability.h, src/fl/channels/encoder_availability.cpp.hpp
EncoderAvailability declares encoder getters and dispatches clockless and SPI chipset configurations to the matching getter. ChipsetVariant dispatch forwards supported types and returns none for unmatched types. Getter definitions return encoder pointers, or null when the relevant optional encoder is disabled.
Typed factory binding
src/fl/channels/channel_typed.h, tests/unit/fl/channels/encoder_availability.cpp
TypedChannel uses dispatch to bind a factory to the selected encoder, or falls back to the shared selector when dispatch returns none. Tests check typed and erased resolution and factory sharing across encoder groups.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant TypedChannel
  participant EncoderAvailability
  participant FactoryBinder
  TypedChannel->>EncoderAvailability: dispatch<FactoryBinder>(chipset)
  EncoderAvailability->>FactoryBinder: pass selected encoder getter
  FactoryBinder->>EncoderAvailability: invoke getter
  EncoderAvailability-->>FactoryBinder: return PixelEncoder
  FactoryBinder-->>TypedChannel: return encoder-bound factory
Loading

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#5163 — This PR extends the typed factory encoder binding introduced for WS2812 to other constant chipsets.
Merge Risk: Minimal · up to 1662c

Typed add() calls now bind each constant chipset to its own encoder, which should reduce binary size for those sketches. No concrete merge-blocking risk was found in the review.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive [#5162] The design meets the issue requirements. EncoderAvailability (src/fl/channels/encoder_availability.h) declares one out-of-line getter per encoder: ws2812(), tm1812(), tm1908(), ucs7604(), ap… Confirm that the head compiles. Either show the definition of FL_ALWAYS_INLINE, or provide a successful build log for src/fl/channels/channel_typed.h and tests/unit/fl/channels/encoder_availability.cpp at the reviewed head. If FL_ALWAYS_INL…
Passed Passed checks: 3 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: it binds each constant typed chipset to its own encoder, which matches the summary (typed factoryFor dispatch, per-encoder getters, new test). The title is a conventio…
Out of Scope Changes check Passed All changes map to the scope of #5162. The edits are in src/fl/channels/channel_typed.h (factoryFor now calls the shared dispatch), src/fl/channels/encoder_availability.h and encoder_availability.cpp.…
Full details: Title check

Explanation

The title names the main change: it binds each constant typed chipset to its own encoder, which matches the summary (typed factoryFor dispatch, per-encoder getters, new test). The title is a conventional-commit style line with a perf scope and an issue reference (#5162). The objectives cite PR #5413 while the title cites #5162, a numbering mismatch that does not affect relevance. The title is 76 characters, within a reasonable length for a title.

Full details: Out of Scope Changes check

Explanation

All changes map to the scope of #5162. The edits are in src/fl/channels/channel_typed.h (factoryFor now calls the shared dispatch), src/fl/channels/encoder_availability.h and encoder_availability.cpp.hpp (per-encoder getters, dispatch, and removal of isWS2812 overloads), and tests/unit/fl/channels/encoder_availability.cpp (new [#5162] test). The PR description states that channel.cpp.hpp and the encoding loops are unchanged. The removed isWS2812 helpers exist only for the WS2812 special case that the issue asks to generalize. The changes keep FASTLED_DISABLE_* decisions in the library, as the issue requires. No unrelated functional change was identified in the summary.

Full details: Linked Issues check

Explanation

[#5162] The design meets the issue requirements. EncoderAvailability (src/fl/channels/encoder_availability.h) declares one out-of-line getter per encoder: ws2812(), tm1812(), tm1908(), ucs7604(), apa102(), sk9822(), ws2801(), ws2803(), p9813(), lpd8806(), lpd6803(), sm16716(), my9221(), hd108(). A single inline dispatch<Binder>() maps every ClocklessChipset encoder, all SpiChipset values, and ChipsetVariant to its getter. Unknown values return Binder::none(). TypedChannel::factoryFor() (src/fl/channels/channel_typed.h) uses this dispatch, so the WS2812 special case is gone. Availability stays library-owned because the header declarations do not depend on FASTLED_DISABLE_* macros.

Open defect: FactoryBinder in channel_typed.h declares bind<Get>() and none() as non-static member functions. dispatch<Binder>() calls them as Binder::template bind<...>() and Binder::none() with no object. As read, this is ill-formed C++ and would not compile. The read did not show the definition of FL_ALWAYS_INLINE (src/fl/stl/compiler_control.h was truncated before it), so this cannot be fully ruled out. The PR reports passing builds and tests, which conflicts with this reading. Behavioral parity of the bound factories and the link-size results could not be verified from source.

Resolution

Confirm that the head compiles. Either show the definition of FL_ALWAYS_INLINE, or provide a successful build log for src/fl/channels/channel_typed.h and tests/unit/fl/channels/encoder_availability.cpp at the reviewed head. If FL_ALWAYS_INLINE does not make these members static, the binder members in FactoryBinder must be declared static for dispatch() to compile. Also provide the bloat report.json or equivalent link evidence for the APA102 and UCS7604 typed sketches, if the size claims need verification.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5159f1b and 1662c12.

Files selected for processing: 4

  • src/fl/channels/channel_typed.h
  • src/fl/channels/encoder_availability.cpp.hpp
  • src/fl/channels/encoder_availability.h
  • tests/unit/fl/channels/encoder_availability.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 22, 2026
@zackees
zackees added this pull request to the merge queue Nov 22, 2026
@github-actions github-actions Bot added sanitized Title, body and conversation screened; review text requires separate screening. and removed sanitized Title, body and conversation screened; review text requires separate screening. labels Nov 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Memory usage (this PR vs. its merge base)

Change in examples/Blink per target. The left number is this PR's image flash / attributed RAM in bytes; the colored delta is the change from the merge base (red ↑ is larger, green ↓ is smaller, Same is unchanged).

Target FLASH [bytes] RAM [bytes]
attiny85 2,460 (Same) 136 (Same)

@github-actions github-actions Bot added sanitized Title, body and conversation screened; review text requires separate screening. and removed sanitized Title, body and conversation screened; review text requires separate screening. labels Nov 22, 2026
@github-actions github-actions Bot added sanitized Title, body and conversation screened; review text requires separate screening. and removed sanitized Title, body and conversation screened; review text requires separate screening. labels Nov 22, 2026
Merged via the queue into master with commit e7374e8 Nov 22, 2026
134 checks passed
@zackees
zackees deleted the fix/5162-channels-typed-fast-path branch November 22, 2026 04:50
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sanitized Title, body and conversation screened; review text requires separate screening.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Channels: typed add<Bus>() fast path covers only WS2812; other constant chipsets still link every encoder

1 participant